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

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

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

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

g = A("g")
n = B("n")
a = C("a")
b = D("b")
c = B("c")
m = C("m")

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

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

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

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

g = A("g")
n = B("n")
a = C("a")
b = D("b")
c = B("c")
m = C("m")

g.s = c
n.o = b
n.p = b
a.p = c
b.x = g
c.o = b
c.p = b
m.p = c
assert c.o.x.s.p.txt == "b"