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

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

a = A("a")
n = B("n")
d = B("d")
c = A("c")
b = A("b")
j = A("j")

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

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

a = A("a")
n = B("n")
d = B("d")
c = A("c")
b = A("b")
j = A("j")

a.q = j
n.u = d
d.u = n
c.q = b
b.q = a
j.q = c
assert a.q.q.q.q.q.q.txt == "c"