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

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

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

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

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

k.v = c
k.q = m
k.p = m
b.z = c
b.u = c
m.r = k
c.r = m
assert m.r.p.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.q: C = None
        self.p: C = None
        self.txt = txt

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

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

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

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

k.v = c
k.q = m
k.p = m
b.z = c
b.u = c
m.r = k
c.r = m
assert m.r.p.r.q.txt == "m"