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.v: B = None
        self.txt = txt

a = A("a")
g = B("g")
n = C("n")

a.q = n
g.s = n
g.r = n
n.v = g
assert a.q.v.s.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.v: B = None
        self.txt = txt

a = A("a")
g = B("g")
n = C("n")

a.q = n
g.s = n
g.r = n
n.v = g
assert a.q.v.s.txt == "n"