#include <bits/stdc++.h>
using namespace std;
const int maxn = 1123456;
int vis[maxn], primes[maxn], id[maxn], p[maxn];
long long a[maxn], buff[maxn], rem[maxn], k;
int pcnt, n;
int main() {
  for (int(i) = (2); (i) <= (1e6); (i)++) {
    if (!vis[i]) {
      vis[i] = i;
      primes[++pcnt] = i;
      id[i] = pcnt;
    }
    for (int(j) = (1); (j) <= (pcnt); (j)++) {
      if (i * primes[j] > 1e6) break;
      vis[i * primes[j]] = primes[j];
      if (i % primes[j] == 0) break;
    }
  }
  scanf("%d", &n);
  for (int(i) = (1); (i) <= (n); (i)++) {
    scanf("%d", p + i);
    scanf("%lld", a + id[p[i]]);
  }
  scanf("%lld", &k);
  fill(rem + 1, rem + pcnt + 1, k);
  bool change;
  do {
    change = false;
    for (int(i) = (1); (i) <= (pcnt); (i)++) {
      if (a[i]) {
        if (!rem[i]) continue;
        long long cur = min(a[i], rem[i]);
        a[i] -= cur, rem[i] -= cur;
        buff[i] += cur - 1;
        change = true;
        int now = primes[i] - 1;
        while (now > 1) {
          a[id[vis[now]]] += cur;
          now /= vis[now];
        }
      } else if (buff[i])
        buff[i]--;
      else if (rem[i])
        rem[i]--;
    }
  } while (change);
  vector<pair<int, long long>> ans;
  for (int(i) = (1); (i) <= (pcnt); (i)++)
    if (a[i]) ans.emplace_back(primes[i], a[i]);
  printf("%d\n", int(ans.size()));
  for (auto it : ans) printf("%d %lld\n", it.first, it.second);
}
