description: The chef has cooked n dishes yet again: the i-th dish consists of a_i grams of fish and b_i grams of meat. 
  
  Banquet organizers consider two dishes i and j equal if a_i=a_j and b_i=b_j at the same time.
  
  The banquet organizers estimate the variety of n dishes as follows. The variety of a set of dishes is equal to the number of different dishes in it. The less variety is, the better.
  
  In order to reduce the variety, a taster was invited. He will eat exactly m_i grams of food from each dish. For each dish, the taster determines separately how much fish and how much meat he will eat. The only condition is that he will eat exactly m_i grams of the i-th dish in total.
  
  Determine how much of what type of food the taster should eat from each dish so that the value of variety is the minimum possible. If there are several correct answers, you may output any of them.
  
  Input
  
  The first line of input data contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases.
  
  Each test case's description is preceded by a blank line. Next comes a line that contains an integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of dishes. Then follows n lines, i-th of which contains three integers a_i, b_i and m_i (0 ≤ a_i, b_i ≤ 10^6; 0 ≤ m_i ≤ a_i+b_i) — the mass of fish in i-th dish, the mass of meat in i-th dish and how many grams in total the taster should eat in i-th dish.
  
  The sum of all n values for all input data sets in the test does not exceed 2 ⋅ 10^5.
  
  Output
  
  For each test case, print on the first line the minimum value of variety that can be achieved by eating exactly m_i grams of food (for all i from 1 to n) from a dish i.
  
  Then print n lines that describe a way to do this: the i-th line should contain two integers x_i and y_i (0 ≤ x_i ≤ a_i; 0 ≤ y_i ≤ b_i; x_i+y_i=m_i), where x_i is how many grams of fish the taster should eat from i-th dish, and y_i is how many grams of meat.
  
  If there are several ways to achieve a minimum balance, print any of them.
  
  Example
  
  Input
  
  
  5
  
  3
  10 10 2
  9 9 0
  10 9 1
  
  2
  3 4 1
  5 1 2
  
  3
  7 2 5
  6 5 4
  5 5 6
  
  1
  13 42 50
  
  5
  5 7 12
  3 1 4
  7 3 7
  0 0 0
  4 1 5
  
  
  Output
  
  
  1
  1 1
  0 0
  1 0
  2
  0 1
  1 1
  2
  3 2
  0 4
  1 5
  1
  8 42
  2
  5 7
  3 1
  4 3
  0 0
  4 1
solution: #include <bits/stdc++.h>
  using namespace std;
  namespace Ruri {
  const int infi = 1e9;
  const long long infl = 4e18;
  }  // namespace Ruri
  using namespace Ruri;
  namespace Gadgets {
  inline long long ceil_div(long long a, long long b) { return (a + b - 1) / b; }
  inline long long pos_mod(long long a, long long b) { return (a % b + b) % b; }
  }  // namespace Gadgets
  namespace Read {
  inline int ri() {
    int x;
    scanf("%d", &x);
    return x;
  }
  inline long long rl() {
    long long x;
    scanf("%lld", &x);
    return x;
  }
  inline double rd() {
    double x;
    scanf("%lf", &x);
    return x;
  }
  }  // namespace Read
  namespace DeBug {}
  using namespace Gadgets;
  using namespace Read;
  using namespace DeBug;
  const int MAX_N = 2e5 + 5;
  int n;
  int a[MAX_N], b[MAX_N], m[MAX_N], t[MAX_N];
  int mna[MAX_N], mxa[MAX_N];
  int id[MAX_N];
  int eat_a[MAX_N], eat_b[MAX_N];
  int main() {
    t[0] = infi;
    int T = ri();
    while (T--) {
      n = ri();
      for (int i = 1, bbb = n; i <= bbb; ++i)
        a[i] = ri(), b[i] = ri(), m[i] = ri(), t[i] = a[i] + b[i] - m[i];
      for (int i = 1, bbb = n; i <= bbb; ++i)
        mna[i] = max(0, a[i] - m[i]), mxa[i] = a[i] - max(0, m[i] - b[i]);
      iota(id + 1, id + 1 + n, 1);
      sort(id + 1, id + 1 + n, [&](int x, int y) {
        if (t[x] != t[y]) return t[x] < t[y];
        return mna[x] != mna[y] ? mna[x] > mna[y] : mxa[x] > mxa[y];
      });
      int variety = 0, mn = 0;
      for (int i = 1, bbb = n; i <= bbb; ++i) {
        int now = id[i];
        if (t[now] != t[id[i - 1]]) {
          ++variety;
          eat_a[now] = a[now] - mna[now];
          eat_b[now] = m[now] - eat_a[now];
          mn = mna[now];
        } else {
          if (mxa[now] >= mn) {
            eat_a[now] = a[now] - mn;
            eat_b[now] = m[now] - eat_a[now];
          } else {
            ++variety;
            eat_a[now] = a[now] - mna[now];
            eat_b[now] = m[now] - eat_a[now];
            mn = mna[now];
          }
        }
      }
      printf("%d\n", variety);
      for (int i = 1, bbb = n; i <= bbb; ++i)
        printf("%d %d\n", eat_a[i], eat_b[i]);
    }
    return 0;
  }
  