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

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

b = A("b")
k = B("k")
e = A("e")
c = B("c")
h = A("h")
a = B("a")

b.q = a
b.t = e
k.x = h
e.q = a
e.t = h
c.x = e
h.q = c
h.t = e
a.x = h
assert b.q.x.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.t: A = None
        self.txt = txt

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

b = A("b")
k = B("k")
e = A("e")
c = B("c")
h = A("h")
a = B("a")

b.q = a
b.t = e
k.x = h
e.q = a
e.t = h
c.x = e
h.q = c
h.t = e
a.x = h
assert b.q.x.q.x.txt == "e"