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

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

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

a = A("a")
h = B("h")
m = C("m")
k = B("k")

a.w = m
a.y = k
h.p = m
h.q = a
m.q = h
k.p = m
k.q = a
assert m.q.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.y: B = None
        self.txt = txt

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

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

a = A("a")
h = B("h")
m = C("m")
k = B("k")

a.w = m
a.y = k
h.p = m
h.q = a
m.q = h
k.p = m
k.q = a
assert m.q.q.w.txt == "m"