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

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

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

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

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

k.r = m
k.u = i
m.r = l
m.v = l
m.w = k
m.p = k
i.s = m
l.q = m
assert k.u.s.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.u: C = None
        self.txt = txt

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

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

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

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

k.r = m
k.u = i
m.r = l
m.v = l
m.w = k
m.p = k
i.s = m
l.q = m
assert k.u.s.r.q.txt == "m"