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

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

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

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

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

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

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

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

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

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

m.x = f
m.p = g
g.o = a
g.q = f
a.s = m
a.v = m
f.w = m
assert m.p.o.s.p.txt == "g"