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 P = 1e9 + 7, INF = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long qpow(long long a, long long n) {
  long long r = 1 % P;
  for (a %= P; n; a = a * a % P, n >>= 1)
    if (n & 1) r = r * a % P;
  return r;
}
long long inv(long long first) {
  return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P;
}
inline int rd() {
  int first = 0;
  char p = getchar();
  while (p < '0' || p > '9') p = getchar();
  while (p >= '0' && p <= '9') first = first * 10 + p - '0', p = getchar();
  return first;
}
const int N = 1e6 + 10;
int n, len, tot;
char s[N];
struct _ {
  int l, r, lid, rid, c;
} f[N];
set<int> g[30];
set<pair<int, int> > A[30], B[30];
vector<pair<int, int> > ans;
int BIT[N];
void add(int first, int v) {
  for (; first <= n; first += first & -first) BIT[first] += v;
}
int qry(int first) {
  int r = first;
  for (; first; first ^= first & -first) r += BIT[first];
  return r;
}
void gao(int l, int r) {
  int lx = qry(l), rx = qry(r);
  len -= rx - lx + 1;
  ans.push_back(pair<int, int>(lx, rx));
  add(r + 1, -rx + lx - 1);
}
void upd(int l, int r, int op) {
  if (op == 1) {
    if (f[l].c == f[r].c)
      B[f[l].c].insert(pair<int, int>(l, r));
    else {
      A[f[l].c].insert(pair<int, int>(l, r));
      A[f[r].c].insert(pair<int, int>(l, r));
    }
  } else {
    if (A[f[l].c].count(pair<int, int>(l, r)))
      A[f[l].c].erase(pair<int, int>(l, r));
    if (A[f[r].c].count(pair<int, int>(l, r)))
      A[f[r].c].erase(pair<int, int>(l, r));
    if (B[f[l].c].count(pair<int, int>(l, r)))
      B[f[l].c].erase(pair<int, int>(l, r));
  }
}
void del(int l, int r) {
  int lx = f[l].l, rx = f[r].r;
  if (lx) upd(lx, l, -1);
  if (rx) upd(r, rx, -1);
  f[lx].r = rx, f[rx].l = lx;
  if (lx && rx) upd(lx, rx, 1);
}
void work() {
  scanf("%s", s + 1);
  n = len = strlen(s + 1);
  for (int i = 1; i <= n; ++i) BIT[i] = 0;
  for (int i = 0; i <= 25; ++i) A[i].clear(), B[i].clear(), g[i].clear();
  ans.clear();
  tot = 0;
  for (int i = 1; i <= n - 1; ++i)
    if (s[i] == s[i + 1]) {
      ++tot;
      f[tot] = {tot - 1, tot + 1, i, i + 1, s[i] - 'a'};
      g[s[i] - 'a'].insert(tot);
      if (tot > 1) upd(tot - 1, tot, 1);
    }
  f[1].l = f[tot].r = 0;
  ans.clear();
  while (tot) {
    int mx = 0, first;
    for (int i = 0; i <= 25; ++i)
      if (g[i].size() > mx) mx = g[i].size(), first = i;
    if (A[first].size()) {
      pair<int, int> u = *A[first].begin();
      A[first].erase(A[first].begin());
      g[f[u.first].c].erase(u.first);
      g[f[u.second].c].erase(u.second);
      if (f[u.first].c == first)
        A[f[u.second].c].erase(u);
      else
        A[f[u.first].c].erase(u);
      del(u.first, u.second);
      gao(f[u.first].rid, f[u.second].lid);
      tot -= 2;
    } else if (B[first].size()) {
      pair<int, int> u = *B[first].begin();
      B[first].erase(B[first].begin());
      g[first].erase(u.second);
      del(u.second, u.second);
      gao(f[u.first].rid, f[u.second].lid);
      tot -= 1;
    } else {
      int u = *g[first].begin();
      g[first].erase(g[first].begin());
      del(u, u);
      gao(f[u].lid, f[u].lid);
      tot -= 1;
    }
  }
  ans.push_back(pair<int, int>(1, len));
  printf("%d\n", (int)ans.size());
  for (auto [first, second] : ans) printf("%d %d\n", first, second);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) work();
}