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

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

j = A("j")
k = B("k")
m = A("m")
g = A("g")
e = B("e")
d = A("d")
a = A("a")
b = A("b")

j.u = d
j.q = e
k.z = e
m.u = a
m.q = e
g.u = b
g.q = k
e.z = k
d.u = b
d.q = k
a.u = j
a.q = k
b.u = a
b.q = e
assert d.u.u.u.u.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.q: B = None
        self.txt = txt

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

j = A("j")
k = B("k")
m = A("m")
g = A("g")
e = B("e")
d = A("d")
a = A("a")
b = A("b")

j.u = d
j.q = e
k.z = e
m.u = a
m.q = e
g.u = b
g.q = k
e.z = k
d.u = b
d.q = k
a.u = j
a.q = k
b.u = a
b.q = e
assert d.u.u.u.u.q.z.txt == "e"