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

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

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

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

k = A("k")
m = B("m")
i = C("i")
d = D("d")
a = C("a")

k.q = m
k.u = m
k.z = a
m.q = d
m.y = a
m.o = k
i.p = a
i.s = d
d.x = k
a.p = i
a.s = d
assert d.x.q.y.s.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.u: B = None
        self.z: C = None
        self.txt = txt

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

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

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

k = A("k")
m = B("m")
i = C("i")
d = D("d")
a = C("a")

k.q = m
k.u = m
k.z = a
m.q = d
m.y = a
m.o = k
i.p = a
i.s = d
d.x = k
a.p = i
a.s = d
assert d.x.q.y.s.txt == "d"