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

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

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

g = A("g")
i = B("i")
a = C("a")
c = B("c")

g.r = i
g.v = a
i.w = a
i.p = a
a.p = g
c.w = a
c.p = a
assert c.w.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.v: C = None
        self.txt = txt

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

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

g = A("g")
i = B("i")
a = C("a")
c = B("c")

g.r = i
g.v = a
i.w = a
i.p = a
a.p = g
c.w = a
c.p = a
assert c.w.p.v.txt == "a"