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

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

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

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

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

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

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