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

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

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

n = A("n")
m = B("m")
i = C("i")
a = B("a")

n.u = m
m.p = i
m.r = a
m.u = n
i.o = n
a.p = i
a.r = m
a.u = n
assert a.r.r.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

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

n = A("n")
m = B("m")
i = C("i")
a = B("a")

n.u = m
m.p = i
m.r = a
m.u = n
i.o = n
a.p = i
a.r = m
a.u = n
assert a.r.r.p.o.txt == "n"