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

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

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

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

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

a.v = k
a.p = n
c.p = m
c.w = k
k.v = c
k.q = c
m.r = n
l.v = k
l.p = m
n.r = m
assert m.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.p: D = None
        self.txt = txt

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

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

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

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

a.v = k
a.p = n
c.p = m
c.w = k
k.v = c
k.q = c
m.r = n
l.v = k
l.p = m
n.r = m
assert m.r.r.r.r.r.txt == "n"