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

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

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

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

c = A("c")
l = B("l")
i = C("i")
d = D("d")

c.r = d
l.q = d
l.y = i
l.t = c
i.z = d
i.o = d
d.y = c
d.p = c
assert d.y.r.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

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

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

c = A("c")
l = B("l")
i = C("i")
d = D("d")

c.r = d
l.q = d
l.y = i
l.t = c
i.z = d
i.o = d
d.y = c
d.p = c
assert d.y.r.p.r.txt == "d"