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

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

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

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

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

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

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

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

n.r = g
n.z = g
n.w = m
b.v = m
m.p = b
g.r = n
g.z = n
g.w = m
assert g.w.p.v.txt == "m"