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

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

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

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

h = A("h")
g = B("g")
e = C("e")
b = D("b")
n = D("n")

h.q = n
g.w = h
g.s = b
e.y = b
e.t = g
b.q = g
b.r = g
b.z = e
n.q = g
n.r = g
n.z = e
assert n.q.s.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

h = A("h")
g = B("g")
e = C("e")
b = D("b")
n = D("n")

h.q = n
g.w = h
g.s = b
e.y = b
e.t = g
b.q = g
b.r = g
b.z = e
n.q = g
n.r = g
n.z = e
assert n.q.s.z.y.txt == "b"