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

class B:
    def __init__(self, txt: str):
        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.x: D = None
        self.q: C = None
        self.p: D = None
        self.s: C = None
        self.txt = txt

n = A("n")
j = B("j")
k = C("k")
g = D("g")
h = D("h")

n.p = h
j.w = n
k.z = j
g.x = h
g.p = h
g.q = k
g.s = k
h.x = g
h.p = g
h.q = k
h.s = k
assert j.w.p.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        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.x: D = None
        self.q: C = None
        self.p: D = None
        self.s: C = None
        self.txt = txt

n = A("n")
j = B("j")
k = C("k")
g = D("g")
h = D("h")

n.p = h
j.w = n
k.z = j
g.x = h
g.p = h
g.q = k
g.s = k
h.x = g
h.p = g
h.q = k
h.s = k
assert j.w.p.p.x.txt == "h"