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

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

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

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

h = A("h")
c = B("c")
m = C("m")
f = D("f")
d = A("d")

h.s = d
h.q = c
h.y = m
c.r = f
c.q = h
m.x = c
m.u = c
m.y = h
f.w = m
f.r = m
d.s = h
d.q = c
d.y = m
assert f.w.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.q: B = None
        self.y: C = None
        self.txt = txt

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

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

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

h = A("h")
c = B("c")
m = C("m")
f = D("f")
d = A("d")

h.s = d
h.q = c
h.y = m
c.r = f
c.q = h
m.x = c
m.u = c
m.y = h
f.w = m
f.r = m
d.s = h
d.q = c
d.y = m
assert f.w.y.y.txt == "m"