Problem: Dreamoon likes strings. Today he created a game about strings:

String s_1, s_2, …, s_n is beautiful if and only if for each 1 ≤ i < n, s_i ≠ s_{i+1}.

Initially, Dreamoon has a string a. In each step Dreamoon can choose a beautiful substring of a and remove it. Then he should concatenate the remaining characters (in the same order).

Dreamoon wants to use the smallest number of steps to make a empty. Please help Dreamoon, and print any sequence of the smallest number of steps to make a empty.

Input

The first line contains an integer t (1 ≤ t ≤ 200 000), denoting the number of test cases in the input.

For each test case, there's one line with a non-empty string of lowercase Latin letters a.

The total sum of lengths of strings in all test cases is at most 200 000.

Output

For each test case, in the first line, you should print m: the smallest number of steps to make a empty. Each of the following m lines should contain two integers l_i, r_i (1 ≤ l_i ≤ r_i ≤ |a|), denoting, that the i-th step is removing the characters from index l_i to r_i in the current string. (indices are numbered starting from 1). 

Note that after the deletion of the substring, indices of remaining characters may change, and r_i should be at most the current length of a.

If there are several possible solutions, you can print any.

Example

Input


4
aabbcc
aaabbb
aaa
abacad


Output


3
3 3
2 4
1 2
3
3 4
2 3
1 2
3
1 1
1 1
1 1
1
1 6

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> v) {
  os << "( " << v.first << ", " << v.second << ")";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i > 0) {
      os << " ";
    }
    os << v[i];
  }
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i > 0) {
      os << endl;
    }
    os << v[i];
  }
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<set<T>> &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i > 0) {
      os << endl;
    }
    os << v[i];
  }
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &v) {
  int i = 0;
  for (auto it : v) {
    if (i > 0) {
      os << ' ';
    }
    os << it;
    i++;
  }
  return os;
}
using Value1 = int;
using Value2 = int;
const Value1 Zero1 = 0;
const Value2 Zero2(-1);
struct Node {
  Value1 sum;
  Value2 lazy;
  Node() : sum(Zero1) { lazy = Zero2; }
};
struct lazy_segtree {
  int N;
  vector<Node> dat;
  lazy_segtree(int n) : N(1) {
    while (N < n) N *= 2;
    dat.resize(2 * N);
    for (int i = 0; i < N; ++i) {
      dat[i + N].sum = Zero1;
    }
    for (int i = N - 1; i >= 1; --i) {
      update_node(i);
    }
  }
  Value2 lazy_connect(const Value2 l, const Value2 r) {
    if (r != -1)
      return r;
    else {
      return l;
    }
  }
  void lazy_func(const int k, const int a, const int b) {
    if (dat[k].lazy != -1) dat[k].sum = dat[k].lazy * (b - a);
  }
  Value1 connect(const Value1 l, const Value1 r) { return l + r; }
  inline void lazy_evaluate_node(int k, int a, int b) {
    lazy_func(k, a, b);
    if (k < N) {
      dat[2 * k].lazy = lazy_connect(dat[2 * k].lazy, dat[k].lazy);
      dat[2 * k + 1].lazy = lazy_connect(dat[2 * k + 1].lazy, dat[k].lazy);
    }
    dat[k].lazy = Zero2;
  }
  inline void update_node(int k) {
    dat[k].sum = connect(dat[2 * k].sum, dat[2 * k + 1].sum);
  }
  void update(int l, int r, Value2 v, int k = 1, int a = 0, int b = -1) {
    if (b == -1) b = N;
    if (l < 0 || r < 0) assert(false);
    lazy_evaluate_node(k, a, b);
    if (b <= l || r <= a) return;
    if (l <= a && b <= r) {
      dat[k].lazy = lazy_connect(dat[k].lazy, v);
      lazy_evaluate_node(k, a, b);
      return;
    }
    int m = (a + b) / 2;
    update(l, r, v, 2 * k, a, m);
    update(l, r, v, 2 * k + 1, m, b);
    update_node(k);
  }
  Value1 get(int l, int r, int k = 1, int a = 0, int b = -1) {
    if (b == -1) b = N;
    if (l < 0 || r < 0) assert(false);
    lazy_evaluate_node(k, a, b);
    if (b <= l || r <= a) return Zero1;
    if (l <= a && b <= r) {
      return dat[k].sum;
    }
    int m = (a + b) / 2;
    Value1 vl = get(l, r, 2 * k, a, m);
    Value1 vr = get(l, r, 2 * k + 1, m, b);
    update_node(k);
    return connect(vl, vr);
  }
};
vector<pair<int, int>> solve(int N, vector<pair<int, int>> vs) {
  vector<pair<int, int>> anss;
  lazy_segtree seg(N);
  seg.update(0, N, 1);
  for (auto p : vs) {
    int l = p.first;
    int r = p.second;
    if (l > r) swap(l, r);
    int al = seg.get(0, l);
    int ar = seg.get(0, r);
    seg.update(l, r, 0);
    anss.emplace_back(al + 1, ar);
  }
  if (seg.get(0, N) != 0) anss.emplace_back(1, seg.get(0, N));
  return anss;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  int T;
  cin >> T;
  while (T--) {
    string st;
    cin >> st;
    vector<set<int>> cs(26);
    for (int i = 0; i < st.size() - 1; ++i) {
      if (st[i] == st[i + 1]) {
        cs[st[i] - 'a'].emplace(i + 1);
      }
    }
    vector<pair<int, int>> answers;
    while (true) {
      pair<int, int> p(-1, -1);
      int cnt = 0;
      for (int i = 0; i < 26; ++i) {
        if (!cs[i].empty()) {
          p = max(p, make_pair(int(cs[i].size()), i));
          cnt++;
        }
      }
      if (cnt == 1 || cnt == 0)
        break;
      else {
        int max_c = p.second;
        pair<int, int> max_l = make_pair(*cs[max_c].begin(), max_c);
        ;
        pair<int, int> other_l = make_pair(int(1e7), -1);
        for (int i = 0; i < 26; ++i) {
          if (i != max_c && !cs[i].empty()) {
            other_l = min(other_l, make_pair(*cs[i].begin(), i));
          }
        }
        bool flag = false;
        {
          pair<int, int> other_m = make_pair(-1, -1);
          for (int i = 0; i < 26; ++i) {
            if (i != max_c && !cs[i].empty()) {
              auto it = cs[i].lower_bound(max_l.first);
              if (it != cs[i].begin()) {
                other_m = max(other_m, make_pair(*prev(it), i));
              }
            }
          }
          if (other_m.first != -1) {
            flag = true;
            answers.emplace_back(max_l.first, other_m.first);
            cs[max_l.second].erase(max_l.first);
            cs[other_m.second].erase(other_m.first);
          }
        }
        if (!flag) {
          pair<int, int> max_m = make_pair(-1, -1);
          {
            auto it = cs[max_l.second].lower_bound(other_l.first);
            { max_m = make_pair(*prev(it), max_c); }
          }
          {
            answers.emplace_back(max_m.first, other_l.first);
            cs[max_m.second].erase(max_m.first);
            cs[other_l.second].erase(other_l.first);
          }
        }
      }
    }
    for (int i = 0; i < 26; ++i) {
      if (!cs[i].empty()) {
        for (auto k : cs[i]) {
          answers.emplace_back(0, k);
        }
      }
    }
    auto ans2 = solve(st.size(), answers);
    cout << ans2.size() << endl;
    for (auto an : ans2) {
      cout << an.first << ' ' << an.second << endl;
    }
  }
  return 0;
}