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

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

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

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

g.s = l
l.v = g
l.r = n
n.v = l
assert g.s.v.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

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

g.s = l
l.v = g
l.r = n
n.v = l
assert g.s.v.s.txt == "l"