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

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

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

g = A("g")
l = B("l")
m = C("m")
i = A("i")

g.s = m
l.p = i
l.t = g
m.q = l
i.s = m
assert g.s.q.t.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

g = A("g")
l = B("l")
m = C("m")
i = A("i")

g.s = m
l.p = i
l.t = g
m.q = l
i.s = m
assert g.s.q.t.s.txt == "m"