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

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

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

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

i = A("i")
j = B("j")
c = C("c")
f = D("f")
e = A("e")

i.t = e
i.x = e
j.t = e
j.z = e
j.q = e
c.s = j
c.p = j
c.w = f
f.w = c
f.x = c
f.t = e
e.t = i
e.x = i
assert f.t.x.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.x: A = None
        self.txt = txt

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

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

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

i = A("i")
j = B("j")
c = C("c")
f = D("f")
e = A("e")

i.t = e
i.x = e
j.t = e
j.z = e
j.q = e
c.s = j
c.p = j
c.w = f
f.w = c
f.x = c
f.t = e
e.t = i
e.x = i
assert f.t.x.t.x.txt == "i"