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

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

e = A("e")
j = B("j")
d = B("d")
n = A("n")
a = A("a")
b = B("b")
m = A("m")
f = B("f")

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

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

e = A("e")
j = B("j")
d = B("d")
n = A("n")
a = A("a")
b = B("b")
m = A("m")
f = B("f")

e.z = n
e.p = f
j.y = f
d.y = j
n.z = e
n.p = d
a.z = e
a.p = f
b.y = d
m.z = n
m.p = f
f.y = d
assert d.y.y.y.y.y.y.txt == "d"