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

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

j = A("j")
g = B("g")
a = A("a")
l = B("l")
f = B("f")
d = A("d")
b = B("b")
h = B("h")
c = B("c")
e = A("e")

j.z = d
g.q = a
a.z = j
l.q = j
f.q = j
d.z = e
b.q = j
h.q = e
c.q = e
e.z = j
assert c.q.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

j = A("j")
g = B("g")
a = A("a")
l = B("l")
f = B("f")
d = A("d")
b = B("b")
h = B("h")
c = B("c")
e = A("e")

j.z = d
g.q = a
a.z = j
l.q = j
f.q = j
d.z = e
b.q = j
h.q = e
c.q = e
e.z = j
assert c.q.z.z.z.z.z.z.txt == "e"