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

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

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

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

n.p = m
n.x = i
i.q = n
m.t = k
m.x = k
m.o = n
k.p = m
k.x = i
assert m.o.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.x: B = None
        self.txt = txt

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

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

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

n.p = m
n.x = i
i.q = n
m.t = k
m.x = k
m.o = n
k.p = m
k.x = i
assert m.o.p.o.txt == "n"