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

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

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

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

i = A("i")
f = B("f")
a = C("a")
e = D("e")

i.t = e
f.x = i
f.v = i
f.z = a
f.q = e
a.p = f
a.u = f
a.x = f
a.w = i
e.u = a
assert i.t.u.w.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: D = None
        self.txt = txt

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

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

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

i = A("i")
f = B("f")
a = C("a")
e = D("e")

i.t = e
f.x = i
f.v = i
f.z = a
f.q = e
a.p = f
a.u = f
a.x = f
a.w = i
e.u = a
assert i.t.u.w.t.txt == "e"