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

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

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

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

l.q = g
g.r = l
g.q = l
m.t = g
assert g.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

l.q = g
g.r = l
g.q = l
m.t = g
assert g.q.q.q.txt == "l"