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

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

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

i = A("i")
f = B("f")
m = C("m")
n = B("n")
b = A("b")
g = C("g")

i.x = n
f.x = n
f.u = g
f.r = i
m.q = f
m.x = g
n.x = f
n.u = m
n.r = i
b.x = f
g.q = f
g.x = m
assert m.q.u.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

i = A("i")
f = B("f")
m = C("m")
n = B("n")
b = A("b")
g = C("g")

i.x = n
f.x = n
f.u = g
f.r = i
m.q = f
m.x = g
n.x = f
n.u = m
n.r = i
b.x = f
g.q = f
g.x = m
assert m.q.u.x.txt == "m"