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

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

m = A("m")
j = B("j")
a = B("a")
f = B("f")
g = B("g")
b = B("b")
h = B("h")
n = A("n")
k = A("k")

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

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

m = A("m")
j = B("j")
a = B("a")
f = B("f")
g = B("g")
b = B("b")
h = B("h")
n = A("n")
k = A("k")

m.u = n
m.z = h
j.q = g
a.q = b
f.q = j
g.q = f
b.q = h
h.q = g
n.u = k
n.z = h
k.u = m
k.z = j
assert a.q.q.q.q.txt == "f"