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

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

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

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

c = A("c")
a = B("a")
k = C("k")
f = D("f")

c.o = f
c.p = f
c.z = k
a.o = c
a.q = c
k.r = a
f.r = a
f.s = k
assert f.s.r.o.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.p: D = None
        self.z: C = None
        self.txt = txt

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

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

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

c = A("c")
a = B("a")
k = C("k")
f = D("f")

c.o = f
c.p = f
c.z = k
a.o = c
a.q = c
k.r = a
f.r = a
f.s = k
assert f.s.r.o.z.txt == "k"