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

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

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

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

a = A("a")
m = B("m")
h = C("h")
i = D("i")
l = A("l")
d = C("d")

a.w = l
a.x = m
a.y = d
a.s = h
m.x = i
h.o = l
i.p = d
i.s = h
i.q = h
i.v = m
l.w = a
l.x = m
l.y = d
l.s = d
d.o = a
assert d.o.s.o.s.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.x: B = None
        self.y: C = None
        self.s: C = None
        self.txt = txt

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

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

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

a = A("a")
m = B("m")
h = C("h")
i = D("i")
l = A("l")
d = C("d")

a.w = l
a.x = m
a.y = d
a.s = h
m.x = i
h.o = l
i.p = d
i.s = h
i.q = h
i.v = m
l.w = a
l.x = m
l.y = d
l.s = d
d.o = a
assert d.o.s.o.s.txt == "d"