#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
const int maxn = 110;
int dp[maxn][maxn*maxn*maxn], n, k, M;
void add(int &a, int b) {
	a = a+b>=M?a+b-M:a+b;
}
int main() {
  	cin.tie(0)->sync_with_stdio(0);
  	cin >> n >> k >> M;
  	dp[0][0] = 1;
  	for(int i = 1; i <= n; i++) {
		for(int sm = 0; sm <= n*n*k; sm++) {
			dp[i][sm] = dp[i-1][sm];
			add(dp[i][sm], dp[i][sm-i]);
			if(sm >= (k+1)*i)
				add(dp[i][sm], M-dp[i-1][sm-(k+1)*i]);
		}
	}
	for(int avg = 1; avg <= n; avg++) {
		int ans = 0;
		for(int sm = 0; sm <= n*n*k; sm++) {
			ans = (ans + dp[avg-1][sm] * 1ll * dp[n-avg][sm])%M;
		}
		ans = ans*1ll*(k+1)%M; ans = (ans+M-1)%M;
		cout << ans << '\n';
	}
}

//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int num[100000];
int kazu[100000];
const int ma = (1 << 16) - 1;
int query(int n) {
	int n2 = (n & ma) + 1;
	while (num[n2]) {
		if (num[n2] == n + 1) return kazu[n2];
		n2 = n2 * 2 % 99991;
	}
	return 0;
}
void add(int n, int b) {
	int n2 = (n & ma) + 1;
	while (num[n2]) {
		if (num[n2] == n + 1) return;
		n2 = n2 * 2 % 99991;
	}
	num[n2] = n + 1;
	kazu[n2] = b;
}
int li[300];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N, M;
	cin >> N >> M;
	int w[8];
	rep(i, N) cin >> w[i];

	pair<int, int> lv[100001];
	rep(i, M) {
		int l, v;
		cin >> l >> v;
		lv[i] = { v, l };
	}
	sort(lv, lv + M);
	lv[M] = { 1e9,1e9 };

	rep(i, 1 << N) {
		rep(j, N) if (i >> j & 1) li[i] += w[j];
	}
	sort(li, li + (1 << N));
	int saidai = 0;
	int k = 0;
	rep(i, 1 << N) {
		while (lv[k].first < li[i]) {
			chmax(saidai, lv[k].second);
			k++;
		}
		add(li[i], saidai);
	}

	rep(i, N) {
		if (w[i] > lv[0].first) {
			co(-1);
			return 0;
		}
	}

	int P[8], K = 1;
	rep(i, N) {
		K *= i + 1;
		P[i] = i;
	}

	ll kotae = 1e9;
	rep(k, K) {
		
		ll tmp[8] = {};
		rep(p, N) {
			int i = P[p];
			int omosa = w[i];
			for (int q = p + 1; q < N; q++) {
				int j = P[q];
				omosa += w[j];
				ll kari = query(omosa);
				chmax(tmp[q], tmp[p] + kari);
			}
		}
		chmin(kotae, tmp[N - 1]);
		next_permutation(P, P + N);
	}

	co(kotae);

	Would you please return 0;
}