#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 9, N = 1e6;
long long val[MAX], pdiv[MAX], n, p, k, cnt;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  for (int i = 2; i <= N; i++)
    if (!pdiv[i])
      for (int j = i; j <= N; j += i)
        if (!pdiv[j]) pdiv[j] = i;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> p, cin >> val[p];
  cin >> k;
  for (int i = 0; k > 0 && i < 20; i++) {
    for (int j = 2; j < N; j++)
      if (val[j] > 0) {
        val[j]--;
        long long cur = j - 1;
        while (cur > 1) val[pdiv[cur]]++, cur /= pdiv[cur];
      }
    k--;
  }
  for (int j = N - 1; j >= 2; j--) {
    long long mi = min(k, val[j]);
    if (val[j] > 0) {
      val[j] -= mi;
      long long cur = j - 1;
      while (cur > 1) val[pdiv[cur]] += mi, cur /= pdiv[cur];
    }
  }
  for (int i = 2; i <= N; i++)
    if (val[i] > 0) cnt++;
  cout << cnt << '\n';
  for (int i = 2; i <= N; i++)
    if (val[i] > 0) cout << i << " " << val[i] << '\n';
}
