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

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

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

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

n.w = b
g.p = b
g.r = n
g.o = n
b.r = g
b.o = n
assert g.r.w.o.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

n.w = b
g.p = b
g.r = n
g.o = n
b.r = g
b.o = n
assert g.r.w.o.txt == "n"