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

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

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

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

g.u = j
g.s = m
j.u = g
i.q = j
m.u = j
m.s = g
assert m.s.u.u.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.s: A = None
        self.txt = txt

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

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

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

g.u = j
g.s = m
j.u = g
i.q = j
m.u = j
m.s = g
assert m.s.u.u.s.txt == "m"