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

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

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

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

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

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

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

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

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

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

k.q = i
k.s = i
m.t = b
m.o = k
b.x = k
b.r = k
i.x = b
assert k.q.x.r.s.txt == "i"