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

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

m = A("m")
f = B("f")
k = B("k")
g = B("g")
j = A("j")
l = A("l")

m.y = l
m.v = f
f.u = g
f.y = j
k.u = f
k.y = j
g.u = k
g.y = l
j.y = l
j.v = g
l.y = m
l.v = k
assert k.u.u.y.v.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.v: B = None
        self.txt = txt

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

m = A("m")
f = B("f")
k = B("k")
g = B("g")
j = A("j")
l = A("l")

m.y = l
m.v = f
f.u = g
f.y = j
k.u = f
k.y = j
g.u = k
g.y = l
j.y = l
j.v = g
l.y = m
l.v = k
assert k.u.u.y.v.txt == "k"