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;
const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
int pct(int x) { return __builtin_popcount(x); }
int bit(int x) { return 31 - __builtin_clz(x); }
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
template <class A>
void re(complex<A>& c);
template <class A, class B>
void re(pair<A, B>& p);
template <class A>
void re(vector<A>& v);
template <class A, size_t SZ>
void re(array<A, SZ>& a);
template <class T>
void re(T& x) {
  cin >> x;
}
void re(double& d) {
  string t;
  re(t);
  d = stod(t);
}
void re(long double& d) {
  string t;
  re(t);
  d = stold(t);
}
template <class H, class... T>
void re(H& h, T&... t) {
  re(h);
  re(t...);
}
template <class A>
void re(complex<A>& c) {
  A a, b;
  re(a, b);
  c = {a, b};
}
template <class A, class B>
void re(pair<A, B>& p) {
  re(p.first, p.second);
}
template <class A>
void re(vector<A>& x) {
  for (auto& a : x) re(a);
}
template <class A, size_t SZ>
void re(array<A, SZ>& x) {
  for (auto& a : x) re(a);
}
template <class A, class B>
string to_string(pair<A, B> p);
template <class A>
string to_string(complex<A> c) {
  return to_string(make_pair(c.real(), c.imag()));
}
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(char c) {
  string second = "";
  second += c;
  return second;
}
string to_string(string second) { return second; }
string to_string(const char* second) { return (string)second; }
string to_string(vector<bool> v) {
  bool fst = 1;
  string res = "{";
  for (int i = (0); i < ((int)v.size()); ++i) {
    if (!fst) res += ", ";
    fst = 0;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t SZ>
string to_string(bitset<SZ> b) {
  string res = "";
  for (int i = (0); i < (SZ); ++i) res += char('0' + b[i]);
  return res;
}
template <class T>
string to_string(T v) {
  bool fst = 1;
  string res = "{";
  for (const auto& x : v) {
    if (!fst) res += ", ";
    fst = 0;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <class A, class B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <class A>
void pr(A x) {
  cout << to_string(x);
}
template <class H, class... T>
void pr(const H& h, const T&... t) {
  pr(h);
  pr(t...);
}
void ps() { pr("\n"); }
template <class H, class... T>
void ps(const H& h, const T&... t) {
  pr(h);
  if (sizeof...(t)) pr(" ");
  ps(t...);
}
void DBG() { cerr << "]" << endl; }
template <class H, class... T>
void DBG(H h, T... t) {
  cerr << to_string(h);
  if (sizeof...(t)) cerr << ", ";
  DBG(t...);
}
void setIn(string second) { freopen(second.c_str(), "r", stdin); }
void setOut(string second) { freopen(second.c_str(), "w", stdout); }
void unsyncIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
void setIO(string second = "") {
  unsyncIO();
  if ((int)second.size()) {
    setIn(second + ".in"), setOut(second + ".out");
  }
}
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
template <class T, int SZ>
struct LazySeg1 {
  T sum[2 * SZ], lazy[2 * SZ];
  LazySeg1() {
    for (int i = (0); i < (2 * SZ); ++i) sum[i] = lazy[i] = 0;
  }
  void push(int ind, int L, int R) {
    if (L != R)
      for (int i = (0); i < (2); ++i) lazy[2 * ind + i] += lazy[ind];
    sum[ind] += (R - L + 1) * lazy[ind];
    lazy[ind] = 0;
  }
  void pull(int ind) { sum[ind] = sum[2 * ind] + sum[2 * ind + 1]; }
  void build() {
    for (int i = (SZ)-1; i >= (1); --i) pull(i);
  }
  void upd(int lo, int hi, T inc, int ind = 1, int L = 0, int R = SZ - 1) {
    push(ind, L, R);
    if (hi < L || R < lo) return;
    if (lo <= L && R <= hi) {
      lazy[ind] = inc;
      push(ind, L, R);
      return;
    }
    int M = (L + R) / 2;
    upd(lo, hi, inc, 2 * ind, L, M);
    upd(lo, hi, inc, 2 * ind + 1, M + 1, R);
    pull(ind);
  }
  T qsum(int lo, int hi, int ind = 1, int L = 0, int R = SZ - 1) {
    push(ind, L, R);
    if (lo > R || L > hi) return 0;
    if (lo <= L && R <= hi) return sum[ind];
    int M = (L + R) / 2;
    return qsum(lo, hi, 2 * ind, L, M) + qsum(lo, hi, 2 * ind + 1, M + 1, R);
  }
};
template <class T, int SZ>
struct LazySeg2 {
  T sum[2 * SZ], lazy[2 * SZ];
  LazySeg2() {
    for (int i = (0); i < (2 * SZ); ++i) sum[i] = lazy[i] = -1;
  }
  void push(int ind, int L, int R) {
    if (lazy[ind] == -1) return;
    if (L != R)
      for (int i = (0); i < (2); ++i) lazy[2 * ind + i] = lazy[ind];
    sum[ind] = lazy[ind] * (R - L + 1);
    lazy[ind] = -1;
  }
  void pull(int ind) { sum[ind] = sum[2 * ind] + sum[2 * ind + 1]; }
  void build() {
    for (int i = (SZ)-1; i >= (1); --i) pull(i);
  }
  void upd(int lo, int hi, int inc, int ind = 1, int L = 0, int R = SZ - 1) {
    push(ind, L, R);
    if (hi < L || R < lo) return;
    if (lo <= L && R <= hi) {
      lazy[ind] = inc;
      push(ind, L, R);
      return;
    }
    int M = (L + R) / 2;
    upd(lo, hi, inc, 2 * ind, L, M);
    upd(lo, hi, inc, 2 * ind + 1, M + 1, R);
    pull(ind);
  }
  T qsum(int lo, int hi, int ind = 1, int L = 0, int R = SZ - 1) {
    push(ind, L, R);
    if (lo > R || L > hi) return 0;
    if (lo <= L && R <= hi) return sum[ind];
    int M = (L + R) / 2;
    return qsum(lo, hi, 2 * ind, L, M) + qsum(lo, hi, 2 * ind + 1, M + 1, R);
  }
};
int n;
string second;
set<pair<int, char>> letnum;
set<pair<int, char>> bigchars;
set<pair<int, pair<int, char>>> par1[26];
set<pair<int, pair<int, char>>> par2[26];
LazySeg1<long long, 262144> lseg1;
LazySeg2<long long, 262144> lseg2;
vector<pair<int, int>> ans;
void SegRemov(int l, int r) {
  int curl = lseg1.qsum(l, l);
  int curr = lseg1.qsum(r, r);
  ans.push_back(make_pair(curl, curr));
  int dec = lseg2.qsum(l, r);
  lseg2.upd(l, r, 0);
  lseg1.upd(r + 1, n, -dec);
}
map<char, int> letnummap;
void updletnum(char a, int inc) {
  letnum.erase(make_pair(letnummap[a], a));
  letnummap[a] += inc;
  letnum.insert(make_pair(letnummap[a], a));
}
void insertpair(pair<int, char> p1, pair<int, char> p2) {
  if (p1.second != p2.second) {
    par1[p1.second - 'a'].insert(
        make_pair(p1.first, make_pair(p2.first, p2.second)));
    par2[p2.second - 'a'].insert(
        make_pair(p2.first, make_pair(p1.first, p1.second)));
  }
}
void removpair(pair<int, char> p1, pair<int, char> p2) {
  if (p1.second != p2.second) {
    par1[p1.second - 'a'].erase(
        make_pair(p1.first, make_pair(p2.first, p2.second)));
    par2[p2.second - 'a'].erase(
        make_pair(p2.first, make_pair(p1.first, p1.second)));
  }
}
void BigRemov(pair<int, char> p) {
  updletnum(p.second, -1);
  pair<int, char> l = make_pair(-1, '0');
  pair<int, char> r = make_pair(-1, '0');
  auto it = bigchars.find(p);
  assert(it != bigchars.end());
  if (it != bigchars.begin()) {
    l = *(prev(it));
  }
  if (it != prev(bigchars.end())) {
    r = *(next(it));
  }
  if (l.first != -1) {
    removpair(l, p);
  }
  if (r.first != -1) {
    removpair(p, r);
  }
  if (l.first != -1 && r.first != -1) {
    insertpair(l, r);
  }
  bigchars.erase(p);
}
int main() {
  setIO();
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> second;
    n = (int)second.size();
    second = "0" + second;
    letnum.clear();
    bigchars.clear();
    ans.clear();
    letnummap.clear();
    for (int i = 0; i < 26; i++) {
      par1[i].clear();
      par2[i].clear();
    }
    for (int i = 1; i <= n; i++) {
      lseg1.upd(i, i, -lseg1.qsum(i, i));
      lseg1.upd(i, i, i);
    }
    lseg2.upd(1, n, 1);
    bool isEZ = true;
    for (int i = 1; i <= n - 1; i++) {
      if (second[i] == second[i + 1]) {
        isEZ = false;
        updletnum(second[i], 1);
        bigchars.insert(make_pair(i, second[i]));
      }
    }
    if (isEZ == true) {
      cout << 1 << "\n" << 1 << " " << n << "\n";
      continue;
    }
    auto it = bigchars.begin();
    while (true) {
      if (next(it) == bigchars.end()) break;
      insertpair(*it, *(next(it)));
      it = next(it);
    }
    while (true) {
      bool charleft0 = 0;
      if ((int)letnum.size() == 0)
        charleft0 = 1;
      else if (prev(letnum.end())->first == 0)
        charleft0 = 1;
      if (charleft0 == 1) {
        SegRemov(1, n);
        break;
      }
      bool charleft1 = 0;
      if ((int)letnum.size() == 1)
        charleft1 = 1;
      else if (prev(prev(letnum.end()))->first == 0)
        charleft1 = 1;
      if (charleft1 == 1) {
        int L = 0;
        int R = 0;
        for (auto u : bigchars) {
          swap(L, R);
          L++;
          R = u.first;
          SegRemov(L, R);
        }
        SegRemov(R + 1, n);
        break;
      }
      pair<int, char> p1, p2;
      p1.second = prev(letnum.end())->second;
      assert((int)par1[p1.second - 'a'].size() >= 1 ||
             (int)par2[p1.second - 'a'].size() >= 1);
      if ((int)par1[p1.second - 'a'].size() >= 1) {
        p1.first = (par1[p1.second - 'a'].begin())->first;
        p2 = (*(par1[p1.second - 'a'].begin())).second;
      } else {
        p1.first = (par2[p1.second - 'a'].begin())->first;
        p2 = (*(par2[p1.second - 'a'].begin())).second;
      }
      int L = p1.first;
      int R = p2.first;
      if (L > R) swap(L, R);
      L++;
      SegRemov(L, R);
      BigRemov(p1);
      BigRemov(p2);
    }
    cout << (int)ans.size() << "\n";
    for (auto u : ans) {
      cout << u.first << " " << u.second << "\n";
    }
  }
}