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

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

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

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

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

a.q = k
m.r = i
i.r = a
i.q = a
k.v = i
k.r = i
k.u = i
n.q = k
assert a.q.r.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

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

a.q = k
m.r = i
i.r = a
i.q = a
k.v = i
k.r = i
k.u = i
n.q = k
assert a.q.r.r.q.txt == "k"