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

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

a = A("a")
i = B("i")
c = B("c")
k = B("k")
n = A("n")
j = B("j")

a.q = i
i.x = k
c.x = i
k.x = i
n.q = j
j.x = c
assert n.q.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

a = A("a")
i = B("i")
c = B("c")
k = B("k")
n = A("n")
j = B("j")

a.q = i
i.x = k
c.x = i
k.x = i
n.q = j
j.x = c
assert n.q.x.x.x.x.txt == "i"