#include <bits/stdc++.h>   using namespace std;   const int N = 2036000;   const long long INF = 199999999999LL;   int n, m;   long long a[N], b[N];   long long first, second, mod;   long long w[N], t[N];   int nn;   void AddA(int &i) {     w[nn] = a[i++];     t[nn++] = 1;   }   void AddB(int &j) {     w[nn] = b[j++];     t[nn++] = 2;   }   int main() {     cin >> n;     cin >> n >> a[0] >> first >> second >> mod;     for (int i = (1); i < (int)(n); i++) a[i] = (a[i - 1] * first + second) % mod;     cin >> m >> b[0] >> first >> second >> mod;     for (int j = (1); j < (int)(m); j++) b[j] = (b[j - 1] * first + second) % mod;     int i = 0, j = 0;     nn = 0;     long long lt = -INF;     while (i < n || j < m) {       if (i == n) {         AddB(j);       } else if (j == m) {         AddA(i);       } else {         bool ga = a[i] >= lt;         bool gb = b[j] >= lt;         if (ga ^ gb) {           if (ga) {             AddA(i);           } else {             AddB(j);           }         } else {           if (a[i] < b[j]) {             AddA(i);           } else {             AddB(j);           }         }       }       lt = w[nn - 1];     }     int bad = 0;     for (int k = (1); k < (int)(nn); k++) bad += (w[k] < w[k - 1]);     cout << bad << endl;     if (n + m <= 200000) {       for (int k = (0); k < (int)(nn); k++) cout << w[k] <<     << t[k] << endl;     }     return 0;   }   