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 int read() {
  char c = getchar();
  int x = 0, f = 1;
  while ((c < '0' || c > '9') && c ^ '-') c = getchar();
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - 48;
    c = getchar();
  }
  return x * f;
}
const int N = 2e5 + 10;
int t, n;
char c[N];
int pos[N], st[N], zhi[N], cnt[27];
int cz[N][2];
inline int max(int x, int y) { return x < y ? y : x; }
inline int min(int x, int y) { return x < y ? x : y; }
inline bool check() {
  int tot = 0, da = 0;
  for (int i = 1; i <= 26; i++) {
    da = max(da, cnt[i]);
    tot += cnt[i];
  }
  return (da << 1) <= tot;
}
struct xds {
  int lazy[N << 2], sum[N << 2];
  inline void upfather(int t) { sum[t] = sum[t << 1] + sum[t << 1 | 1]; }
  void build(int t, int l, int r) {
    sum[t] = lazy[t] = 0;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(t << 1, l, mid);
    build(t << 1 | 1, mid + 1, r);
  }
  inline void pushdown(int t, int l, int r) {
    if (!lazy[t]) return;
    int mid = (l + r) >> 1;
    sum[t << 1] = mid - l + 1;
    sum[t << 1 | 1] = r - mid;
    lazy[t << 1] = lazy[t << 1 | 1] = 1;
    lazy[t] = 0;
    return;
  }
  void gai(int t, int l, int r, int ql, int qr) {
    if (ql > r || qr < l) return;
    if (ql <= l && qr >= r) {
      sum[t] = r - l + 1;
      lazy[t] = 1;
      return;
    }
    if (lazy[t]) pushdown(t, l, r);
    int mid = (l + r) >> 1;
    gai(t << 1, l, mid, ql, qr);
    gai(t << 1 | 1, mid + 1, r, ql, qr);
    upfather(t);
  }
  int cha(int t, int l, int r, int ql, int qr) {
    if (ql > r || qr < l) return 0;
    if (ql <= l && qr >= r) return sum[t];
    if (lazy[t]) pushdown(t, l, r);
    int mid = (l + r) >> 1;
    return cha(t << 1, l, mid, ql, qr) + cha(t << 1 | 1, mid + 1, r, ql, qr);
  }
} T;
int main() {
  t = read();
  while (t--) {
    memset(cnt, 0, sizeof(cnt));
    scanf("%s", c + 1);
    n = strlen(c + 1);
    int m = 0, top = 0, sl = 0;
    for (int i = 2; i <= n; i++)
      if (c[i] == c[i - 1]) {
        pos[++m] = i;
        zhi[m] = c[i] - 96;
      }
    int da = 0;
    for (int i = 1; i <= m; i++) cnt[zhi[i]]++;
    for (int i = 1; i <= 26; i++)
      if (cnt[i] > cnt[da]) da = i;
    if ((cnt[da] << 1) <= m) {
      if (m & 1) cnt[zhi[m--]]--;
      for (int i = 1; i <= m; i++) {
        if (!top || zhi[i] == zhi[st[top]])
          st[++top] = i;
        else {
          cnt[zhi[i]]--;
          cnt[zhi[st[top]]]--;
          if (check()) {
            sl++;
            cz[sl][0] = pos[st[top]];
            cz[sl][1] = pos[i] - 1;
            top--;
          } else
            cnt[zhi[i]]++, cnt[zhi[st[top]]]++, st[++top] = i;
        }
      }
    } else {
      for (int i = 1; i <= m; i++) {
        if (zhi[i] == da) {
          if (!top || zhi[st[top]] == da)
            st[++top] = i;
          else {
            sl++;
            cz[sl][0] = pos[st[top]];
            cz[sl][1] = pos[i] - 1;
            top--;
          }
        } else {
          if (!top || zhi[st[top]] ^ da)
            st[++top] = i;
          else {
            sl++;
            cz[sl][0] = pos[st[top]];
            cz[sl][1] = pos[i] - 1;
            top--;
          }
        }
      }
    }
    T.build(1, 1, n);
    for (int i = 1; i <= sl; i++) {
      int x = cz[i][0] - T.cha(1, 1, n, 1, cz[i][0]);
      int y = cz[i][1] - T.cha(1, 1, n, 1, cz[i][1]);
      T.gai(1, 1, n, cz[i][0], cz[i][1]);
      cz[i][0] = x;
      cz[i][1] = y;
    }
    int las = 0;
    for (int i = 1, wu = 1; i <= n; i++) {
      int pan = T.cha(1, 1, n, i, i);
      if (!pan) {
        if (!las || las == c[i] - 96) {
          ++sl;
          cz[sl][0] = cz[sl][1] = 1;
        } else
          ++cz[sl][1];
        las = c[i] - 96;
      }
    }
    cout << sl << "\n";
    for (int i = 1; i <= sl; i++) cout << cz[i][0] << " " << cz[i][1] << "\n";
  }
  return 0;
}