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

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

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

m = A("m")
f = B("f")
b = C("b")
h = A("h")
a = C("a")
g = B("g")

m.s = h
f.w = a
f.q = m
b.t = h
h.s = m
a.t = h
g.w = a
g.q = m
assert a.t.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

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

m = A("m")
f = B("f")
b = C("b")
h = A("h")
a = C("a")
g = B("g")

m.s = h
f.w = a
f.q = m
b.t = h
h.s = m
a.t = h
g.w = a
g.q = m
assert a.t.s.s.s.s.s.txt == "m"