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

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

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

b = A("b")
h = B("h")
m = C("m")

b.q = h
h.p = m
h.y = b
m.p = h
m.s = h
assert b.q.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

b = A("b")
h = B("h")
m = C("m")

b.q = h
h.p = m
h.y = b
m.p = h
m.s = h
assert b.q.p.s.txt == "h"