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

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

b = A("b")
d = B("d")
c = B("c")
g = A("g")
h = B("h")
j = B("j")

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

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

b = A("b")
d = B("d")
c = B("c")
g = A("g")
h = B("h")
j = B("j")

b.u = c
d.z = h
d.q = c
c.z = d
c.q = d
g.u = h
h.z = d
h.q = j
j.z = h
j.q = d
assert h.q.q.q.z.z.txt == "h"