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

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

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

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

g.q = m
a.s = g
a.q = g
m.q = g
m.t = a
assert a.q.q.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: A = None
        self.q: A = None
        self.txt = txt

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

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

g.q = m
a.s = g
a.q = g
m.q = g
m.t = a
assert a.q.q.q.txt == "g"