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

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

g = A("g")
j = B("j")
d = B("d")
f = B("f")
c = A("c")
m = B("m")
n = A("n")
h = B("h")
e = B("e")
l = B("l")

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

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

g = A("g")
j = B("j")
d = B("d")
f = B("f")
c = A("c")
m = B("m")
n = A("n")
h = B("h")
e = B("e")
l = B("l")

g.z = n
g.u = c
j.p = g
d.p = n
f.p = c
c.z = n
c.u = n
m.p = n
n.z = c
n.u = g
h.p = g
e.p = g
l.p = n
assert j.p.u.u.u.z.u.u.u.z.z.txt == "n"