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

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

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

h = A("h")
i = B("i")
m = C("m")
g = A("g")
d = C("d")
b = B("b")

h.t = m
h.p = g
h.w = g
i.y = b
m.r = d
m.q = g
m.t = h
g.t = m
g.p = h
g.w = h
d.r = m
d.q = g
d.t = g
b.y = i
assert m.q.p.t.q.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.p: A = None
        self.w: A = None
        self.txt = txt

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

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

h = A("h")
i = B("i")
m = C("m")
g = A("g")
d = C("d")
b = B("b")

h.t = m
h.p = g
h.w = g
i.y = b
m.r = d
m.q = g
m.t = h
g.t = m
g.p = h
g.w = h
d.r = m
d.q = g
d.t = g
b.y = i
assert m.q.p.t.q.t.txt == "m"