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

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

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

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

f = A("f")
g = B("g")
e = C("e")
n = D("n")

f.q = g
f.x = e
g.p = n
g.o = n
g.u = e
g.s = f
e.p = n
e.s = f
n.p = f
n.t = f
n.s = f
n.r = e
assert g.p.s.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.x: C = None
        self.txt = txt

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

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

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

f = A("f")
g = B("g")
e = C("e")
n = D("n")

f.q = g
f.x = e
g.p = n
g.o = n
g.u = e
g.s = f
e.p = n
e.s = f
n.p = f
n.t = f
n.s = f
n.r = e
assert g.p.s.x.p.txt == "n"