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

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

j = A("j")
m = B("m")
g = B("g")
f = A("f")
i = B("i")
b = B("b")
l = A("l")

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

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

j = A("j")
m = B("m")
g = B("g")
f = A("f")
i = B("i")
b = B("b")
l = A("l")

j.t = l
j.q = g
m.x = i
g.x = m
f.t = l
f.q = g
i.x = b
b.x = i
l.t = j
l.q = g
assert l.t.q.x.x.x.x.x.txt == "b"