def move_forward(i, v, g01, g23):
    """
    Helper function to build pillowcase covers

    EXAMPLES::

        sage: from surface_dynamics.flat_surfaces.separatrix_diagram import move_forward
        sage: g23 = [1,2,0]
        sage: g01 = [2,0,1]
        sage: i,v = 0,0
        sage: for _ in range(6):
        ....:     i,v = move_forward(i, v, g01, g23)
        ....:     print("%d %d" % (i,v))
        0 1
        1 0
        1 1
        2 0
        2 1
        0 0

        sage: i,v = 0,2
        sage: for _ in range(6):
        ....:     i,v = move_forward(i, v, g01, g23)
        ....:     print("%d %d" % (i,v))
        0 3
        2 2
        2 3
        1 2
        1 3
        0 2
    """
    if v == 0:
        v = 1
    elif v == 2:
        v = 3
    elif v == 1:
        v = 0
        i = g23[i]
    elif v == 3:
        v = 2
        i = g01[i]
    else:
        raise ValueError
    return i, v
