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

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

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

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

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

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

b.u = e
f.x = e
f.q = n
g.u = f
n.u = f
l.u = e
d.u = e
e.x = f
e.q = l
assert e.x.x.x.x.txt == "e"