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

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

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

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

m = A("m")
k = B("k")
g = C("g")
b = D("b")
c = B("c")
i = A("i")
d = B("d")

m.x = k
m.o = d
k.w = c
g.s = m
g.o = b
b.x = g
c.w = k
i.x = k
i.o = d
d.w = k
assert d.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.o: B = None
        self.txt = txt

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

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

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

m = A("m")
k = B("k")
g = C("g")
b = D("b")
c = B("c")
i = A("i")
d = B("d")

m.x = k
m.o = d
k.w = c
g.s = m
g.o = b
b.x = g
c.w = k
i.x = k
i.o = d
d.w = k
assert d.w.w.w.w.txt == "c"