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

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

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

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

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

n.y = j
n.q = d
n.x = g
n.p = l
g.y = i
g.o = j
i.z = n
l.s = d
l.q = d
l.u = g
j.y = n
j.q = d
j.x = g
j.p = l
d.z = n
assert n.q.z.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.q: C = None
        self.x: B = None
        self.p: D = None
        self.txt = txt

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

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

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

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

n.y = j
n.q = d
n.x = g
n.p = l
g.y = i
g.o = j
i.z = n
l.s = d
l.q = d
l.u = g
j.y = n
j.q = d
j.x = g
j.p = l
d.z = n
assert n.q.z.q.z.txt == "n"