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

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

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

class D:
    def __init__(self, txt: str):
        self.z: C = None
        self.y: B = None
        self.r: D = None
        self.txt = txt

a = A("a")
i = B("i")
h = C("h")
m = D("m")
n = D("n")
j = A("j")

a.z = j
a.p = h
i.t = a
h.s = n
h.p = n
h.z = i
m.z = h
m.y = i
m.r = n
n.z = h
n.y = i
n.r = m
j.z = a
j.p = h
assert n.y.t.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.p: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.z: C = None
        self.y: B = None
        self.r: D = None
        self.txt = txt

a = A("a")
i = B("i")
h = C("h")
m = D("m")
n = D("n")
j = A("j")

a.z = j
a.p = h
i.t = a
h.s = n
h.p = n
h.z = i
m.z = h
m.y = i
m.r = n
n.z = h
n.y = i
n.r = m
j.z = a
j.p = h
assert n.y.t.z.p.txt == "h"