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

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

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

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

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

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

m.z = a
i.q = c
i.p = c
b.q = c
b.p = g
f.z = b
g.q = b
g.p = a
c.q = a
c.p = g
n.q = c
n.p = c
j.z = i
a.q = c
a.p = b
h.z = g
assert i.p.q.p.p.p.q.p.p.txt == "a"