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

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

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

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

n = A("n")
j = B("j")
l = C("l")
g = D("g")
i = C("i")

n.r = l
n.z = l
n.s = i
j.z = g
l.o = i
l.z = i
l.s = n
g.x = l
i.o = l
i.z = l
i.s = n
assert n.z.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.s: C = None
        self.z: C = None
        self.txt = txt

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

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

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

n = A("n")
j = B("j")
l = C("l")
g = D("g")
i = C("i")

n.r = l
n.z = l
n.s = i
j.z = g
l.o = i
l.z = i
l.s = n
g.x = l
i.o = l
i.z = l
i.s = n
assert n.z.s.s.txt == "i"