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

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

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

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

h = A("h")
c = B("c")
l = C("l")
f = D("f")
g = B("g")

h.y = g
h.u = g
h.s = c
h.z = f
c.s = h
l.s = c
f.w = l
f.q = h
g.s = h
assert g.s.u.s.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.u: B = None
        self.s: B = None
        self.z: D = None
        self.txt = txt

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

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

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

h = A("h")
c = B("c")
l = C("l")
f = D("f")
g = B("g")

h.y = g
h.u = g
h.s = c
h.z = f
c.s = h
l.s = c
f.w = l
f.q = h
g.s = h
assert g.s.u.s.txt == "h"