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

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

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

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

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

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

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

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

b.v = n
b.o = n
b.s = g
n.p = g
n.r = b
g.z = b
assert b.v.r.v.txt == "n"