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

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

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

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

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

k.r = h
k.y = h
k.s = h
d.z = k
d.o = h
h.t = e
h.r = k
h.v = k
e.q = k
assert k.y.v.y.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.y: C = None
        self.s: C = None
        self.txt = txt

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

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

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

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

k.r = h
k.y = h
k.s = h
d.z = k
d.o = h
h.t = e
h.r = k
h.v = k
e.q = k
assert k.y.v.y.r.txt == "k"