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>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline T parse(const string &s) {
  T x;
  stringstream ss(s);
  ss >> x;
  return x;
}
const double EPS = 1e-12;
const int INF = 1000 * 1000 * 1000;
const long long LINF = INF * 1ll * INF;
const double DINF = 1e200;
const double PI = 3.1415926535897932384626433832795l;
int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
long long gcdex(long long a, long long b, long long &x, long long &y) {
  if (!a) {
    x = 0, y = 1;
    return b;
  }
  long long k = b / a;
  long long g = gcdex(b - k * a, a, y, x);
  x -= k * y;
  return g;
}
long long inv(long long a, long long m) {
  assert(m > 1);
  long long x, y, g;
  g = gcdex(a, m, x, y);
  return (x % (m / g) + m / g) % m / g;
}
long long crt(long long a1, long long m1, long long a2, long long m2) {
  long long a = (a2 - a1 % m2 + m2) % m2;
  long long x, y, g;
  g = gcdex(m1, m2, x, y);
  if (a % g) return -1;
  long long m = m1 / g * m2;
  assert(x + m2 >= 0);
  x = a / g * (x + m2) % m2;
  long long r = (a1 + x * m1) % m;
  assert(r % m1 == a1 && r % m2 == a2);
  return r;
}
long long powmod(long long a, long long p, long long m) {
  assert(p >= 0);
  long long r = 1;
  while (p) {
    if (p & 1) r = r * a % m;
    p >>= 1;
    a = a * a % m;
  }
  return r;
}
bool isprime(long long a) {
  if (a <= 1) return false;
  for (long long i = 2; i * i <= a; ++i) {
    if (a % i == 0) return false;
  }
  return true;
}
long long sqrtup(long long a) {
  if (!a) return 0;
  long long x = max(0ll, (long long)sqrt((double)a));
  while (x * x >= a) --x;
  while ((x + 1) * (x + 1) < a) ++x;
  return x + 1;
}
long long isqrt(long long a) {
  if (a <= 0) {
    assert(!a);
    return 0;
  }
  long long x = (long long)sqrt((double)a);
  while (sqr(x + 1) <= a) ++x;
  while (x * x > a) --x;
  return x;
}
long long sgn(long long x) { return x < 0 ? -1 : x > 0 ? 1 : 0; }
double randf() {
  double m = RAND_MAX + 1.;
  return (((rand() + .5) / m + rand()) / m + rand()) / m;
}
template <class T>
ostream &operator<<(ostream &s, const vector<T> &v);
template <class A, class B>
ostream &operator<<(ostream &s, const pair<A, B> &p);
template <class K, class V>
ostream &operator<<(ostream &s, const map<K, V> &m);
template <class T>
ostream &operator<<(ostream &s, const set<T> &m);
template <class T, size_t N>
ostream &operator<<(ostream &s, const array<T, N> &a);
template <class... T>
ostream &operator<<(ostream &s, const tuple<T...> &t);
template <class T>
ostream &operator<<(ostream &s, const vector<T> &v) {
  s << '[';
  for (int i = 0; i < (((int)(v).size())); ++i) {
    if (i) s << ',';
    s << v[i];
  }
  s << ']';
  return s;
}
template <class A, class B>
ostream &operator<<(ostream &s, const pair<A, B> &p) {
  s << "(" << p.first << "," << p.second << ")";
  return s;
}
template <class K, class V>
ostream &operator<<(ostream &s, const map<K, V> &m) {
  s << "{";
  bool f = false;
  for (const auto &it : m) {
    if (f) s << ",";
    f = true;
    s << it.first << ": " << it.second;
  }
  s << "}";
  return s;
}
template <class T>
ostream &operator<<(ostream &s, const set<T> &m) {
  s << "{";
  bool f = false;
  for (const auto &it : m) {
    if (f) s << ",";
    f = true;
    s << it;
  }
  s << "}";
  return s;
}
template <class T>
ostream &operator<<(ostream &s, const multiset<T> &m) {
  s << "{";
  bool f = false;
  for (const auto &it : m) {
    if (f) s << ",";
    f = true;
    s << it;
  }
  s << "}";
  return s;
}
template <class T, class V, class C>
ostream &operator<<(ostream &s, const priority_queue<T, V, C> &q) {
  auto a = q;
  s << "{";
  bool f = false;
  while (!a.empty()) {
    if (f) s << ",";
    f = true;
    s << a.top();
    a.pop();
  }
  return s << "}";
}
template <class T, size_t N>
ostream &operator<<(ostream &s, const array<T, N> &a) {
  s << '[';
  for (int i = 0; i < (((int)(a).size())); ++i) {
    if (i) s << ',';
    s << a[i];
  }
  s << ']';
  return s;
}
template <class T>
ostream &operator<<(ostream &s, const deque<T> &a) {
  s << '[';
  for (int i = 0; i < (((int)(a).size())); ++i) {
    if (i) s << ',';
    s << a[i];
  }
  s << ']';
  return s;
}
template <size_t n, class... T>
struct put1 {
  static ostream &put(ostream &s, const tuple<T...> &t) {
    s << get<sizeof...(T) - n>(t);
    if (n > 1) s << ',';
    return put1<n - 1, T...>::put(s, t);
  }
};
template <class... T>
struct put1<0, T...> {
  static ostream &put(ostream &s, const tuple<T...> &t) { return s; }
};
template <class... T>
ostream &operator<<(ostream &s, const tuple<T...> &t) {
  s << "(";
  put1<sizeof...(T), T...>::put(s, t);
  s << ")";
  return s;
}
ostream &put3(ostream &s, const char *, bool) { return s; }
template <class U, class... T>
ostream &put3(ostream &s, const char *f, bool fs, U &&u, T &&...t) {
  while (*f == ' ') ++f;
  if (!fs) s << ", ";
  auto nf = f;
  int d = 0;
  while (*nf && (*nf != ',' || d)) {
    if (*nf == '(')
      ++d;
    else if (*nf == ')')
      --d;
    ++nf;
  }
  auto nf2 = nf;
  while (nf2 > f && *(nf2 - 1) == ' ') --nf;
  fs = *f == '"';
  if (!fs) {
    s.write(f, nf2 - f);
    s << "=";
  };
  s << u;
  if (fs) s << ' ';
  if (*nf) ++nf;
  return put3(s, nf, fs, forward<T>(t)...);
}
struct segtree {
  vector<int> T;
  segtree(int n) : T(n * 4) {}
  void add(int l, int r, int v, int a, int b, int k) {
    if (l >= b || r <= a) return;
    if (l <= a && r >= b) {
      T[k] += v;
      return;
    }
    int c = (a + b) / 2;
    add(l, r, v, a, c, k * 2 + 1);
    add(l, r, v, c, b, k * 2 + 2);
  }
  int get(int p, int a, int b, int k) {
    if (b == a + 1) return T[k];
    int c = (a + b) / 2;
    if (p < c)
      return T[k] + get(p, a, c, k * 2 + 1);
    else
      return T[k] + get(p, c, b, k * 2 + 2);
  }
};
int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  srand(35964);
  int tc;
  cin >> tc;
  for (int qq = 0; qq < (tc); ++qq) {
    string A;
    cin >> A;
    map<int, int> B;
    array<int, 26> C{};
    array<set<int>, 26> D;
    for (int i = 0; i < (((int)(A).size()) - 1); ++i) {
      if (A[i] == A[i + 1]) {
        if (((int)(B).size())) {
          pair<int, int> t = *B.rbegin();
          if (t.second != A[i] - 'a') {
            D.at(t.second).insert(t.first);
            D.at(A[i] - 'a').insert(t.first);
          }
        }
        B[i + 1] = A[i] - 'a';
        ++C.at(A[i] - 'a');
      }
    }
    do {
    } while (false);
    segtree T(((int)(A).size()));
    vector<pair<int, int> > R;
    auto turn = [&](int a, int b) {
      int da = T.get(a, 0, ((int)(A).size()), 0);
      int db = T.get(b - 1, 0, ((int)(A).size()), 0);
      R.push_back(make_pair(a - da, b - db));
      do {
      } while (false);
      T.add(a, ((int)(A).size()), b - db - a + da, 0, ((int)(A).size()), 0);
    };
    while (true) {
      pair<int, int> mx(-1, -1);
      for (int i = 0; i < (26); ++i) mx = max(mx, make_pair(C[i], i));
      if (!mx.first || !((int)(D.at(mx.second)).size())) break;
      int a = *D[mx.second].begin();
      auto it1 = B.find(a);
      assert(it1 != B.end());
      auto it2 = it1;
      ++it2;
      assert(it2 != B.end());
      int b = it2->first;
      assert(it1->second != it2->second);
      assert(b);
      turn(a, b);
      D[it1->second].erase(it1->first);
      D[it2->second].erase(it1->first);
      --C[it1->second];
      --C[it2->second];
      auto it3 = it2;
      ++it3;
      if (it3 != B.end() && it3->second != it2->second) {
        D[it2->second].erase(it2->first);
        D[it3->second].erase(it2->first);
      }
      auto it0 = it1;
      if (it1 != B.begin()) {
        --it0;
        if (it0->second != it1->second) {
          D[it0->second].erase(it0->first);
          D[it1->second].erase(it0->first);
        }
      }
      if (it1 != B.begin() && it3 != B.end() && it0->second != it3->second) {
        D[it0->second].insert(it0->first);
        D[it3->second].insert(it0->first);
      }
      B.erase(it1);
      B.erase(it2);
    }
    do {
    } while (false);
    int p = 0;
    while (((int)(B).size())) {
      turn(p, B.begin()->first);
      p = B.begin()->first;
      B.erase(B.begin());
    }
    turn(p, ((int)(A).size()));
    cout << ((int)(R).size()) << '\n';
    for (int i = 0; i < (((int)(R).size())); ++i)
      cout << R[i].first + 1 << ' ' << R[i].second << '\n';
  }
  return 0;
}