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

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

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

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

m = A("m")
b = B("b")
f = C("f")
k = D("k")
i = C("i")

m.u = k
m.s = k
b.q = i
f.o = k
f.r = m
f.p = b
k.o = f
k.y = b
i.o = k
i.r = m
i.p = b
assert f.p.q.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.s: D = None
        self.txt = txt

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

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

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

m = A("m")
b = B("b")
f = C("f")
k = D("k")
i = C("i")

m.u = k
m.s = k
b.q = i
f.o = k
f.r = m
f.p = b
k.o = f
k.y = b
i.o = k
i.r = m
i.p = b
assert f.p.q.r.s.txt == "k"