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

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

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

i = A("i")
d = B("d")
h = C("h")
a = B("a")
m = B("m")

i.q = d
i.s = a
d.y = h
h.w = i
a.y = h
m.y = h
assert d.y.w.s.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: B = None
        self.txt = txt

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

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

i = A("i")
d = B("d")
h = C("h")
a = B("a")
m = B("m")

i.q = d
i.s = a
d.y = h
h.w = i
a.y = h
m.y = h
assert d.y.w.s.y.txt == "h"