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

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

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

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

n.x = g
n.s = g
i.u = g
i.q = n
i.r = n
g.x = n
assert i.r.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.s: C = None
        self.txt = txt

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

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

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

n.x = g
n.s = g
i.u = g
i.q = n
i.r = n
g.x = n
assert i.r.x.x.txt == "n"