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

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

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

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

k = A("k")
e = B("e")
j = C("j")
a = D("a")
b = A("b")

k.x = a
k.y = a
k.z = j
e.p = a
j.r = b
a.p = e
a.t = e
a.o = j
a.s = k
b.x = a
b.y = a
b.z = j
assert a.t.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.z: C = None
        self.y: D = None
        self.txt = txt

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

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

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

k = A("k")
e = B("e")
j = C("j")
a = D("a")
b = A("b")

k.x = a
k.y = a
k.z = j
e.p = a
j.r = b
a.p = e
a.t = e
a.o = j
a.s = k
b.x = a
b.y = a
b.z = j
assert a.t.p.s.txt == "k"