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

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

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

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

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

g.t = i
d.u = g
d.x = k
k.x = g
k.s = i
k.v = i
k.p = d
i.z = g
assert k.x.t.z.txt == "
class A:
    def __init__(self, txt: str):
        self.t: D = None
        self.txt = txt

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

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

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

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

g.t = i
d.u = g
d.x = k
k.x = g
k.s = i
k.v = i
k.p = d
i.z = g
assert k.x.t.z.txt == "g"