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

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

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

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

n = A("n")
c = B("c")
a = C("a")
g = D("g")

n.z = a
n.s = a
n.r = g
n.x = c
c.u = g
a.x = c
g.u = a
g.z = n
g.o = n
g.s = n
assert n.x.u.u.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.s: C = None
        self.r: D = None
        self.x: B = None
        self.txt = txt

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

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

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

n = A("n")
c = B("c")
a = C("a")
g = D("g")

n.z = a
n.s = a
n.r = g
n.x = c
c.u = g
a.x = c
g.u = a
g.z = n
g.o = n
g.s = n
assert n.x.u.u.x.txt == "c"