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

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

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

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

k = A("k")
m = B("m")
j = C("j")
g = D("g")
c = D("c")

k.u = g
m.w = k
m.t = c
j.v = m
g.v = j
g.u = k
c.v = j
c.u = k
assert c.v.v.w.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

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

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

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

k = A("k")
m = B("m")
j = C("j")
g = D("g")
c = D("c")

k.u = g
m.w = k
m.t = c
j.v = m
g.v = j
g.u = k
c.v = j
c.u = k
assert c.v.v.w.u.txt == "g"