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

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

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

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

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

k.u = d
k.z = f
a.q = d
a.x = d
a.w = k
g.x = d
g.v = i
d.r = f
d.x = a
d.z = g
i.x = d
i.v = g
f.u = d
f.z = k
assert f.u.z.v.x.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.z: A = None
        self.txt = txt

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

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

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

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

k.u = d
k.z = f
a.q = d
a.x = d
a.w = k
g.x = d
g.v = i
d.r = f
d.x = a
d.z = g
i.x = d
i.v = g
f.u = d
f.z = k
assert f.u.z.v.x.r.z.txt == "k"