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

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

b = A("b")
a = B("a")
f = B("f")
n = A("n")
c = B("c")
e = B("e")

b.u = a
a.r = n
a.q = f
f.r = b
f.q = a
n.u = f
c.r = n
c.q = e
e.r = n
e.q = c
assert c.q.q.r.u.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

b = A("b")
a = B("a")
f = B("f")
n = A("n")
c = B("c")
e = B("e")

b.u = a
a.r = n
a.q = f
f.r = b
f.q = a
n.u = f
c.r = n
c.q = e
e.r = n
e.q = c
assert c.q.q.r.u.q.q.txt == "f"