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

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

f = A("f")
n = B("n")
l = A("l")
m = B("m")
g = B("g")
j = A("j")

f.u = j
f.z = j
n.p = j
n.q = j
l.u = f
l.z = f
m.p = l
m.q = l
g.p = f
g.q = f
j.u = l
j.z = l
assert f.u.u.u.u.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.z: A = None
        self.txt = txt

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

f = A("f")
n = B("n")
l = A("l")
m = B("m")
g = B("g")
j = A("j")

f.u = j
f.z = j
n.p = j
n.q = j
l.u = f
l.z = f
m.p = l
m.q = l
g.p = f
g.q = f
j.u = l
j.z = l
assert f.u.u.u.u.z.z.txt == "f"