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

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

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

m = A("m")
g = B("g")
c = C("c")
f = A("f")

m.v = c
m.p = f
g.s = m
g.p = f
c.o = g
f.v = c
f.p = m
assert f.p.v.o.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.p: A = None
        self.txt = txt

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

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

m = A("m")
g = B("g")
c = C("c")
f = A("f")

m.v = c
m.p = f
g.s = m
g.p = f
c.o = g
f.v = c
f.p = m
assert f.p.v.o.txt == "g"