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

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

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

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

g = A("g")
f = B("f")
h = C("h")
k = D("k")

g.x = k
g.q = k
g.s = h
f.r = h
f.x = h
f.w = g
h.z = f
k.t = g
k.x = f
assert f.w.s.z.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.q: D = None
        self.s: C = None
        self.txt = txt

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

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

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

g = A("g")
f = B("f")
h = C("h")
k = D("k")

g.x = k
g.q = k
g.s = h
f.r = h
f.x = h
f.w = g
h.z = f
k.t = g
k.x = f
assert f.w.s.z.x.txt == "h"