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

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

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

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

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

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

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

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

n.w = g
n.p = b
b.z = g
f.o = n
g.o = n
assert g.o.p.z.o.txt == "n"