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

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

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

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

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

d.w = f
d.u = k
m.v = a
k.w = i
a.u = m
a.x = m
a.v = d
f.w = d
f.u = i
i.w = k
assert f.u.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.u: C = None
        self.txt = txt

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

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

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

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

d.w = f
d.u = k
m.v = a
k.w = i
a.u = m
a.x = m
a.v = d
f.w = d
f.u = i
i.w = k
assert f.u.w.w.w.txt == "k"