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

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

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

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

c.q = b
h.s = b
h.r = b
b.s = c
assert h.r.s.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

c.q = b
h.s = b
h.r = b
b.s = c
assert h.r.s.q.txt == "b"