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

class B:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

m = A("m")
g = B("g")
a = C("a")
k = D("k")

m.w = g
m.p = g
g.p = a
a.u = g
a.x = m
a.o = m
a.s = k
k.x = a
assert a.x.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.p: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

m = A("m")
g = B("g")
a = C("a")
k = D("k")

m.w = g
m.p = g
g.p = a
a.u = g
a.x = m
a.o = m
a.s = k
k.x = a
assert a.x.p.p.txt == "a"