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

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

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

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

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

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

n.z = a
n.s = d
a.p = d
m.z = d
m.s = a
d.p = a
h.z = d
h.s = a
g.z = a
g.s = a
b.z = d
b.s = d
j.z = a
j.s = d
assert d.p.p.p.p.p.p.txt == "d"