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

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

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

class D:
    def __init__(self, txt: str):
        self.p: A = None
        self.o: B = None
        self.u: C = None
        self.r: B = None
        self.txt = txt

j = A("j")
k = B("k")
n = C("n")
a = D("a")
f = A("f")

j.p = f
j.z = n
k.u = n
n.z = k
a.p = f
a.o = k
a.r = k
a.u = n
f.p = j
f.z = n
assert j.z.z.u.z.u.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.z: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.p: A = None
        self.o: B = None
        self.u: C = None
        self.r: B = None
        self.txt = txt

j = A("j")
k = B("k")
n = C("n")
a = D("a")
f = A("f")

j.p = f
j.z = n
k.u = n
n.z = k
a.p = f
a.o = k
a.r = k
a.u = n
f.p = j
f.z = n
assert j.z.z.u.z.u.txt == "n"