#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000000 + 10;
int n;
int prime[MAX];
long long K, be[MAX];
vector<pair<long long, long long> > line[MAX];
int top;
pair<long long, long long> st[MAX];
int main() {
  int i, j;
  scanf("%d", &n);
  for ((i) = (1); (i) <= (n); ++(i)) {
    int first;
    scanf("%d", &first);
    cin >> be[first];
  }
  cin >> K;
  for ((i) = (2); (i) != (MAX); ++(i))
    if (!prime[i])
      for (j = i + i; j < MAX; j += i) prime[j] = 1;
  vector<pair<int, long long> > ans;
  for (i = MAX - 1; i >= 2; --i)
    if (!prime[i]) {
      top = 0;
      if (be[i]) st[++top] = make_pair(0, be[i]);
      for (j = i; j + 1 < MAX; j += i)
        if (!prime[j + 1]) {
          int k = 0;
          int t = j, num = 0, to = j + 1;
          for (; t % i == 0; t /= i) ++num;
          for ((k) = (0); (k) != ((int)line[to].size()); ++(k))
            if (line[to][k].first < K)
              st[++top] = make_pair(
                  line[to][k].first + 1,
                  (min(K, line[to][k].second) - line[to][k].first) * num);
        }
      sort(st + 1, st + top + 1);
      long long r = -1, l = 0;
      for ((j) = (1); (j) <= (top); ++(j)) {
        if (r < st[j].first) {
          if (r != -1) line[i].push_back(make_pair(l, r));
          l = st[j].first;
          r = st[j].first;
        }
        r += st[j].second;
      }
      if (r != -1) line[i].push_back(make_pair(l, r));
      if (line[i].size() && (--line[i].end())->second > K)
        ans.push_back(make_pair(i, (--line[i].end())->second - K));
    }
  reverse(ans.begin(), ans.end());
  printf("%d\n", ans.size());
  for ((i) = (0); (i) != ((int)ans.size()); ++(i))
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
