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

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

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

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

f = A("f")
m = B("m")
h = C("h")
n = D("n")
a = C("a")

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

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

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

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

f = A("f")
m = B("m")
h = C("h")
n = D("n")
a = C("a")

f.w = n
m.w = n
m.y = a
m.o = a
h.v = n
h.q = n
h.p = n
h.s = a
n.y = f
n.t = m
n.x = m
a.v = n
a.q = n
a.p = n
a.s = h
assert m.o.p.y.w.txt == "n"