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;
inline long long read() {
  long long nm = 0;
  bool fh = true;
  char cw = getchar();
  for (; !isdigit(cw); cw = getchar()) fh ^= (cw == '-');
  for (; isdigit(cw); cw = getchar()) nm = nm * 10 + (cw - '0');
  return fh ? nm : -nm;
}
set<int> bl[30], br[30], S;
int fl[200020], fr[200020], t[200020], c[200020], n, L[200020], R[200020], m,
    sm[30];
char ch[200020];
inline void add(int k, int x) {
  for (; k <= n; k += (k & -k)) c[k] += x;
}
inline int qry(int k, int tt = 0) {
  for (; k; k -= (k & -k)) tt += c[k];
  return tt;
}
inline int fdl(int x) { return x == fl[x] ? x : fl[x] = fdl(fl[x]); }
inline int fdr(int x) { return x == fr[x] ? x : fr[x] = fdr(fr[x]); }
inline void _Ins(int a, int b) {
  if (t[a] != t[b]) {
    bl[t[a]].insert(a), br[t[b]].insert(b);
  }
}
inline void _Del(int a, int b) {
  if (t[a] != t[b]) {
    bl[t[a]].erase(a), br[t[b]].erase(b);
  }
}
inline void Ins(int a) {
  ++sm[t[a]], S.insert(a);
  set<int>::iterator it = S.find(a);
  int pr, sf;
  --it, pr = (*it), ++it, ++it, sf = (*it);
  if (pr >= 1 && sf <= n) _Del(pr, sf);
  if (pr >= 1) _Ins(pr, a);
  if (sf <= n) _Ins(a, sf);
}
inline void Del(int a) {
  --sm[t[a]];
  set<int>::iterator it = S.find(a);
  int pr, sf;
  --it, pr = (*it), ++it, ++it, sf = (*it), --it, S.erase(it);
  if (pr >= 1) _Del(pr, a);
  if (sf <= n) _Del(a, sf);
  if (pr >= 1 && sf <= n) _Ins(pr, sf);
}
inline void del(int x) {
  int l = fdl(x - 1), r = fdr(x + 1);
  if (t[l] == t[x]) Del(l);
  if (t[x] == t[r]) Del(x);
  if (t[l] == t[r]) Ins(l);
  fl[x] = x - 1, fr[x] = x + 1, add(x, -1);
}
inline void calc(int w) {
  if (!bl[w].empty()) {
    int x = (*bl[w].begin()), y;
    x = fdr(x + 1), L[m] = R[m] = qry(x), del(x);
    for (y = fdr(x); y <= n && t[y] != t[x]; x = y, del(y), y = fdr(y)) R[m]++;
  } else {
    int x = (*br[w].begin()), y;
    L[m] = R[m] = qry(x), del(x);
    for (y = fdl(x); y >= 1 && t[y] != t[x]; x = y, del(y), y = fdl(y)) L[m]--;
  }
}
inline void solve() {
  scanf("%s", ch + 1), n = strlen(ch + 1), S.clear(), m = 0;
  for (int i = 1; i <= n; i++) c[i] = 0, t[i] = ch[i] - 'a', fl[i] = fr[i] = i;
  for (int i = 1; i <= n; i++) add(i, 1);
  t[0] = -1, t[n + 1] = -2, fr[n + 1] = n + 1, S.insert(0), S.insert(n + 1);
  for (int i = 0; i < 26; i++) bl[i].clear(), br[i].clear(), sm[i] = 0;
  for (int i = 1; i < n; i++)
    if (t[i] == t[i + 1]) Ins(i);
  while (fdr(1) <= n) {
    int w = -1, mx = -1, sum = 0;
    ++m;
    for (int i = 0; i < 26; sum += sm[i], i++)
      if (sm[i] > mx) mx = sm[i], w = i;
    if (sum < 2 || sum == mx) {
      int x = fdr(1), las = x;
      del(x), L[m] = R[m] = 1;
      for (int y = fdr(las); y <= n && t[y] != t[las];
           las = y, del(y), y = fdr(las), ++R[m])
        ;
    } else
      calc(w);
  }
  printf("%d\n", m);
  for (int i = 1; i <= m; i++) printf("%d %d\n", L[i], R[i]);
}
int main() {
  for (int Cas = read(); Cas; --Cas) solve();
  return 0;
}