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

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

a = A("a")
h = B("h")
e = B("e")
j = A("j")
c = B("c")
d = A("d")
k = B("k")

a.y = d
a.p = d
h.z = e
e.z = c
j.y = d
j.p = d
c.z = h
d.y = a
d.p = a
k.z = h
assert a.p.p.y.p.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.p: A = None
        self.txt = txt

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

a = A("a")
h = B("h")
e = B("e")
j = A("j")
c = B("c")
d = A("d")
k = B("k")

a.y = d
a.p = d
h.z = e
e.z = c
j.y = d
j.p = d
c.z = h
d.y = a
d.p = a
k.z = h
assert a.p.p.y.p.y.y.txt == "a"