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.z: A = None
        self.txt = txt

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

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

k.v = m
k.p = f
c.z = k
m.u = c
m.r = f
f.v = m
f.p = k
assert k.p.p.v.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.z: A = None
        self.txt = txt

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

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

k.v = m
k.p = f
c.z = k
m.u = c
m.r = f
f.v = m
f.p = k
assert k.p.p.v.txt == "m"