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

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

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

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

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

n.u = a
g.u = n
g.x = i
i.x = n
a.w = i
a.y = i
a.o = n
a.p = j
j.w = i
j.y = i
j.o = n
j.p = a
assert g.x.x.u.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

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

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

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

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

n.u = a
g.u = n
g.x = i
i.x = n
a.w = i
a.y = i
a.o = n
a.p = j
j.w = i
j.y = i
j.o = n
j.p = a
assert g.x.x.u.w.x.txt == "n"