class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.v: B = None
        self.x: A = None
        self.txt = txt

a = A("a")
l = B("l")
k = B("k")
m = A("m")
g = A("g")
h = B("h")

a.y = m
l.v = h
l.x = a
k.v = h
k.x = m
m.y = a
g.y = a
h.v = k
h.x = g
assert l.x.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.v: B = None
        self.x: A = None
        self.txt = txt

a = A("a")
l = B("l")
k = B("k")
m = A("m")
g = A("g")
h = B("h")

a.y = m
l.v = h
l.x = a
k.v = h
k.x = m
m.y = a
g.y = a
h.v = k
h.x = g
assert l.x.y.y.txt == "a"