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

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

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

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

c = A("c")
d = B("d")
h = C("h")
k = D("k")

c.o = h
c.y = d
c.p = d
d.p = c
h.p = k
k.r = d
k.z = c
k.y = c
assert c.o.p.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.y: B = None
        self.p: B = None
        self.txt = txt

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

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

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

c = A("c")
d = B("d")
h = C("h")
k = D("k")

c.o = h
c.y = d
c.p = d
d.p = c
h.p = k
k.r = d
k.z = c
k.y = c
assert c.o.p.r.p.txt == "c"