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;
int inline read() {
  int num = 0, neg = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    num = (num << 3) + (num << 1) + c - '0';
    c = getchar();
  }
  return num * neg;
}
const int maxn = 200010, mod = 998244353;
int T, n, cnt, t[26], mx, tp, stk[maxn], b[maxn];
char str[maxn], a[maxn], pos;
vector<pair<int, int> > op;
struct SGT {
  int sum[maxn << 2], cov[maxn << 2];
  void pushup(int x) { sum[x] = sum[(x << 1)] + sum[(x << 1 | 1)]; }
  void pushdown(int x) {
    if (!cov[x]) return;
    sum[(x << 1)] = 0;
    sum[(x << 1 | 1)] = 0;
    cov[(x << 1)] = 1;
    cov[(x << 1 | 1)] = 1;
    cov[x] = 0;
  }
  void Build(int x, int l, int r) {
    cov[x] = 0;
    if (l == r) {
      sum[x] = 1;
      return;
    }
    int mid = l + r >> 1;
    Build((x << 1), l, mid);
    Build((x << 1 | 1), mid + 1, r);
    pushup(x);
  }
  void upd(int x, int l, int r, int L, int R) {
    if (l >= L && r <= R) {
      sum[x] = 0;
      cov[x] = 1;
      return;
    }
    int mid = l + r >> 1;
    pushdown(x);
    if (mid >= L) upd((x << 1), l, mid, L, R);
    if (mid < R) upd((x << 1 | 1), mid + 1, r, L, R);
    pushup(x);
  }
  int Q(int x, int l, int r, int L, int R) {
    if (l >= L && r <= R) return sum[x];
    int mid = l + r >> 1, ans = 0;
    pushdown(x);
    pushup(x);
    if (mid >= L) ans += Q((x << 1), l, mid, L, R);
    if (mid < R) ans += Q((x << 1 | 1), mid + 1, r, L, R);
    return ans;
  }
} s;
char Find() {
  int mx = 0;
  char pos = 0;
  for (int i = 0; i < 26; i++)
    if (t[i] >= mx) mx = t[i], pos = i + 'a';
  return pos;
}
bool can(int x, int y) {
  if (x == y) return 0;
  t[x]--;
  t[y]--;
  int p = cnt - 2;
  char pos = Find();
  if (t[pos - 'a'] * 2 > p) {
    t[x]++;
    t[y]++;
    return 0;
  } else {
    cnt = p;
    return 1;
  }
}
void work(int l, int r) {
  int posl = s.Q(1, 1, n, 1, l);
  int posr = s.Q(1, 1, n, 1, r);
  if (posl == 0 && posr == 0) return;
  op.push_back(make_pair(posl, posr));
  s.upd(1, 1, n, l, r);
}
int main() {
  T = read();
  while (T--) {
    scanf("%s", str + 1);
    n = strlen(str + 1);
    s.Build(1, 1, n);
    cnt = tp = 0;
    op.clear();
    for (int i = 2; i <= n; i++)
      if (str[i] == str[i - 1]) a[++cnt] = str[i], b[cnt] = i;
    for (int i = 0; i < 26; i++) t[i] = 0;
    for (int i = 1; i <= cnt; i++) t[a[i] - 'a']++;
    mx = 0;
    pos = 0;
    for (int i = 0; i < 26; i++)
      if (t[i] > mx) mx = t[i], pos = i + 'a';
    if (2 * mx > cnt) {
      for (int i = 1; i <= cnt; i++) {
        if (a[i] != pos) {
          if (tp && a[stk[tp]] == pos)
            work(b[stk[tp]], b[i] - 1), tp--;
          else
            stk[++tp] = i;
        } else {
          if (tp && a[stk[tp]] != pos)
            work(b[stk[tp]], b[i] - 1), tp--;
          else
            stk[++tp] = i;
        }
      }
      for (int i = 1; i < tp; i++) work(b[stk[i]], b[stk[i + 1]] - 1);
      if (tp) work(b[stk[tp]], b[stk[tp]]);
    } else {
      int st = (cnt & 1) ? 2 : 1;
      int C = cnt;
      if (st == 2) t[a[1] - 'a']--;
      for (int i = st; i <= C; i++)
        if (tp && can(a[stk[tp]] - 'a', a[i] - 'a'))
          work(b[stk[tp]], b[i] - 1), tp--;
        else
          stk[++tp] = i;
      if (st == 2) work(b[1], b[1]);
    }
    work(1, n);
    printf("%d\n", op.size());
    for (int i = 0; i < op.size(); i++)
      printf("%d %d\n", op[i].first, op[i].second);
  }
  return 0;
}