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

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

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

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

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

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

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

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

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

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

h.s = d
c.p = h
c.y = d
d.q = c
a.o = c
a.z = c
a.r = h
assert h.s.q.y.txt == "d"