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

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

f = A("f")
g = B("g")
m = B("m")
d = A("d")
l = B("l")
b = A("b")
h = A("h")

f.t = m
f.q = g
g.r = h
m.r = h
d.t = g
d.q = g
l.r = h
b.t = g
b.q = m
h.t = l
h.q = l
assert g.r.q.r.t.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.q: B = None
        self.txt = txt

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

f = A("f")
g = B("g")
m = B("m")
d = A("d")
l = B("l")
b = A("b")
h = A("h")

f.t = m
f.q = g
g.r = h
m.r = h
d.t = g
d.q = g
l.r = h
b.t = g
b.q = m
h.t = l
h.q = l
assert g.r.q.r.t.r.q.txt == "l"