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

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

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

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

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

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

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

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

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

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

h.o = n
h.w = n
h.y = l
m.q = h
m.s = f
f.y = m
n.v = m
l.o = n
l.w = n
l.y = h
assert m.s.y.s.y.txt == "m"