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

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

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

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

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

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

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

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

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

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

k.u = d
b.p = c
b.r = c
b.u = d
d.v = m
c.v = b
i.u = d
m.u = d
assert k.u.v.u.v.txt == "m"