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

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

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

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

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

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

h.t = c
l.r = h
l.q = e
b.r = h
b.q = l
e.r = h
e.q = l
c.t = h
k.r = c
k.q = b
assert b.r.t.t.t.txt == "c"