// Arup Guha
// 12/1/2024
// Solution to CIS 3362 Homework 7

import java.util.*;

public class ecpoints {

	public static void main(String[] args) {
		
		// Get input data.
		Scanner stdin = new Scanner(System.in);
		long p = stdin.nextLong();
		long a = stdin.nextLong();
		long b = stdin.nextLong();
		
		// Loop through all x coordinates.
		for (long x=0; x<p; x++) {
		
			// Get corresponding value of y squared.
			long ysq = (x*x*x+a*x+b)%p;
			
			// Skip if it's not a perfect square.
			if (!isSquare(p, ysq)) continue;
			
			// Find values and print.
			ArrayList<Long> ys = getSquares(p, ysq);
			for (long y: ys)
				System.out.println(x+" "+y);
		}
	}
	
	// Returns b to the e mod m. Requires m > 1.
	public static long modpow(long b, long e, long m) {
	
		// Base case.
		if (e == 0) return 1;
			
		// Time savings here.
		if (e%2 == 0) {
			long tmp = modpow(b, e/2, m);
			return (tmp*tmp)%m;
		}
		
		// Slow case.
		return (modpow(b,e-1,m)*b)%m;
	}
	
	// Pre-condition: p is a prime that is 3 mod 4, 0 <= x < p.
	// Post-condition: Returns true iff there is some integer c such that c^2 = x mod p.
	public static boolean isSquare(long p, long x) {
	
		// This always works.
		if (x == 0) return true;
		
		// Out criteria.
		return modpow(x, (p-1)/2, p) == 1;
	}
	
	// Pre-condition: p is a prime that is 3 mod 4, 0 <= x < p and x is a quadratic residue mod p.
	// Returns the value(s) of c for which c^2 = x mod p.
	public static ArrayList<Long> getSquares(long p, long x) {
	
		// Store answers here.
		ArrayList<Long> res = new ArrayList<Long>();
		
		// Get this case out of the way.
		if (x == 0) {
			res.add(0L);
			return res;
		}
		
		// Use our formula to get one answer, then add reflection...
		long ans = modpow(x, (p+1)/4, p);
		res.add(ans);
		res.add(p-ans);
		Collections.sort(res);
		return res;
	}
}
	