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

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

m = A("m")
b = B("b")
j = A("j")
n = A("n")
e = A("e")
f = B("f")
l = B("l")
d = B("d")

m.y = d
b.q = f
b.u = m
j.y = b
n.y = l
e.y = d
f.q = b
f.u = e
l.q = b
l.u = n
d.q = b
d.u = n
assert l.u.y.q.q.u.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

m = A("m")
b = B("b")
j = A("j")
n = A("n")
e = A("e")
f = B("f")
l = B("l")
d = B("d")

m.y = d
b.q = f
b.u = m
j.y = b
n.y = l
e.y = d
f.q = b
f.u = e
l.q = b
l.u = n
d.q = b
d.u = n
assert l.u.y.q.q.u.y.q.txt == "b"