# Arup Guha
# 12/1/2024
# Solution to CIS 3362 Homework 7

# Pre-condition: p is a prime that is 3 mod 4 and 0 <= x < p
# Post-condition: returns true iff there is some
#                 integer c such that c^2 = x mod p
def isSquare(p, x):

    # Special case.
    if x == 0:
        return True

    # For primes 3 mod 4, this works!
    return pow(x,(p-1)//2,p) == 1

# Pre-condition: p is a prime 3 mod 4 and x is a possible remainder when
#                perfect square is divided by p. (quadratic residue)
# Post-condition: Returns a list storing the integers c such that c^2 = x mod p
def getSquares(p, x):

    res = []

    # Special case.
    if x == 0:
        res.append(0)
        return res

    # Calculate both answers, add and sort.
    ans = pow(x, (p+1)//4, p)
    res.append(ans)
    res.append(p-ans)
    res.sort()
    return res

def main():

    # Get input.
    toks = input().split()
    p = int(toks[0])
    a = int(toks[1])
    b = int(toks[2])

    # Loop through all values of x.
    for x in range(p):

        ysq = (x*x*x + a*x + b)%p

        # Skip these.
        if not isSquare(p, ysq):
            continue

        # Get the matching y's and print.
        yvals = getSquares(p, ysq)
        for y in yvals:
            print(x,y)

# Run it!
main()
