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

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

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

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

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

a.s = h
a.y = m
g.u = a
h.u = i
h.q = i
h.v = i
i.q = a
m.s = h
m.y = a
assert a.s.v.q.y.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.y: A = None
        self.txt = txt

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

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

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

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

a.s = h
a.y = m
g.u = a
h.u = i
h.q = i
h.v = i
i.q = a
m.s = h
m.y = a
assert a.s.v.q.y.s.txt == "h"