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

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

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

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

m.r = c
g.u = c
g.x = m
g.q = m
c.t = g
c.w = m
assert g.q.r.t.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

m.r = c
g.u = c
g.x = m
g.q = m
c.t = g
c.w = m
assert g.q.r.t.txt == "g"