//* Problem  : F - Fractran
//* Contest  : acm.tju.edu.cn
//* Origin   : University of Ulm Local Contest 2004
//* Type     : Solution
//* Date     : 2008.06.07
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 8.0

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <iostream>
using namespace std;
#define int64 long long
#define INF 1000000000
#define EPS 1E-8

#define ALL(a) a.begin(), a.end()
#define PB(a, v) a.push_back(v)
#define MP(a,b) make_pair(a, b)
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
#define FORO(i, obj) for (int i = 0; i < (int)(obj.size); i++)

#define MAX 175

int n, m, k;

vector <pair<int, int> > nom[128], denom[128];

int num[1024];

inline int power2()
{
	if (num[2] == num[0]) return num[2] + 1;
	return 0;
}

int is_prime(int n)
{
	for (int k = 2; k * k <= n; k++)
		if (n % k == 0) return 0;
	return 1;
}

int prime[1024];

void fact(int n, int *a)
{
	for (int k = 2; k * k <= n; k++)
		while (n % k == 0)
		{
			a[0]++; a[k]++; n /= k;
		}
	if (n > 1)
	{
		a[n]++; a[0]++;
	}
}

void fact2(int n, vector <pair<int, int> > &a)
{
	a.clear();
	for (int k = 2; k * k <= n; k++)
		if (n % k == 0)
		{
			int cnt = 0;
			while (n % k == 0)
			{
				cnt++; n /= k;
			}
			a.push_back(MP(k, cnt));
		}
	if (n > 1)
	{
		a.push_back(MP(n, 1));
	}
}


int div(int k)
{
	int f = 1;
	for (int i = 0; i < denom[k].size(); i++)
		if (num[denom[k][i].first] < denom[k][i].second) return 0;
	for (int i = 0; i < denom[k].size(); i++)
	{
		num[denom[k][i].first] -= denom[k][i].second;
		num[0] -= denom[k][i].second;
	}
	for (int i = 0; i < nom[k].size(); i++)
	{
		num[nom[k][i].first] += nom[k][i].second;
		num[0] += nom[k][i].second;
	}
	return 1;
}

int main()
{
#ifdef _DEBUG
	freopen("1166.in", "r", stdin);
#endif
	for (int i = 0; i < 1024; i++)
		prime[i] = is_prime(i);
	while (scanf("%d%d%d", &m, &n, &k) == 3 && m)
	{
		memset(num, 0, sizeof(num));
		for (int i = 0; i < k; i++)
		{
			int nn, dnn;
			scanf("%d%d", &nn, &dnn);
			fact2(nn, nom[i]);
			fact2(dnn, denom[i]);
		}
		fact(n, num);
		int cnt = 0;
		while (1)
		{
			int t = power2();
			if (t)
			{
				if (cnt) putchar(' '); cnt++;
				printf("%d", t - 1);
				if (cnt == m) break;
			}
			for (int i = 0; i < k; i++)
				if (div(i)) break;
		}
		putchar('\n');

	}
	return 0;
}
