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>
struct node {
  int l, r;
} tmp[200005];
char a[200005], b[200005];
int tag[800005], sum[800005];
int tot[355], resL[200005], resR[200005], st[200005], p[200005], tmpL[200005],
    tmpR[200005];
inline bool cmp1(node x, node y) { return x.l < y.l; }
inline bool cmp2(node x, node y) { return x.r > y.r; }
inline void build(int p, int l, int r) {
  tag[p] = -1;
  sum[p] = 0;
  if (l == r) {
    sum[p] = 1;
    return;
  }
  int mid = l + r >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  sum[p] = sum[p << 1] + sum[p << 1 | 1];
}
inline void spread(int p, int l, int r) {
  int mid = l + r >> 1;
  if (tag[p] != -1) {
    tag[p << 1] = tag[p << 1 | 1] = tag[p];
    sum[p << 1] = (mid - l + 1) * tag[p];
    sum[p << 1 | 1] = (r - mid) * tag[p];
    tag[p] = -1;
  }
}
inline void change(int p, int l, int r, int L, int R, int val) {
  if (L <= l && r <= R) {
    sum[p] = (r - l + 1) * val;
    tag[p] = val;
    return;
  }
  spread(p, l, r);
  int mid = l + r >> 1;
  if (L <= mid) change(p << 1, l, mid, L, R, val);
  if (R > mid) change(p << 1 | 1, mid + 1, r, L, R, val);
  sum[p] = sum[p << 1] + sum[p << 1 | 1];
}
inline int ask(int p, int l, int r, int L, int R) {
  if (L <= l && r <= R) return sum[p];
  spread(p, l, r);
  int mid = l + r >> 1, res = 0;
  if (L <= mid) res += ask(p << 1, l, mid, L, R);
  if (R > mid) res += ask(p << 1 | 1, mid + 1, r, L, R);
  return res;
}
inline int askPos(int p, int l, int r) {
  if (l == r) return l;
  int mid = l + r >> 1;
  if (sum[p << 1])
    return askPos(p << 1, l, mid);
  else
    return askPos(p << 1 | 1, mid + 1, r);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int top = 0, m = 0, num = 0, len = 0, ans = 0, res = 0, now, pos1, pos2;
    scanf("%s", a + 1);
    len = strlen(a + 1);
    for (register char ch = 'a'; ch <= 'z'; ++ch) tot[ch] = 0;
    for (register int i = 1; i <= len; ++i)
      if (a[i] == a[i + 1]) {
        ++tot[a[i]];
        p[++num] = i;
        b[num] = a[i];
      }
    m = num;
    pos1 = 1;
    pos2 = len;
    build(1, 1, len);
    for (now = 1; now <= num; ++now) {
      for (register char ch = 'a'; ch <= 'z'; ++ch)
        res = tot[res] > tot[ch] ? res : ch;
      if (2 * tot[res] >= m) break;
      if (!top) {
        st[++top] = now;
      } else {
        if (b[st[top]] == b[now]) {
          st[++top] = now;
        } else {
          --tot[b[st[top]]];
          --tot[b[now]];
          resL[++ans] = ask(1, 1, len, 1, p[st[top]] + 1);
          resR[ans] = ask(1, 1, len, 1, p[now]);
          tmpL[ans] = p[st[top]] + 1;
          tmpR[ans] = p[now];
          change(1, 1, len, p[st[top]] + 1, p[now], 0);
          --top;
          m -= 2;
        }
      }
    }
    if (m) {
      for (; now <= num; ++now) {
        if (!top || b[st[top]] == b[now] ||
            (b[st[top]] != res && b[now] != res)) {
          st[++top] = now;
        } else {
          --tot[b[st[top]]];
          --tot[b[now]];
          resL[++ans] = ask(1, 1, len, 1, p[st[top]] + 1);
          resR[ans] = ask(1, 1, len, 1, p[now]);
          tmpL[ans] = p[st[top]] + 1;
          tmpR[ans] = p[now];
          change(1, 1, len, p[st[top]] + 1, p[now], 0);
          --top;
          m -= 2;
        }
      }
    }
    for (register int t = 1; t <= top; ++t) {
      int pos = askPos(1, 1, len);
      --tot[b[st[t]]];
      resL[++ans] = ask(1, 1, len, 1, pos);
      resR[ans] = ask(1, 1, len, 1, p[st[t]]);
      tmpL[ans] = pos;
      tmpR[ans] = p[st[t]];
      change(1, 1, len, pos, p[st[t]], 0);
    }
    printf("%d\n", ans + 1);
    for (register int i = 1; i <= ans; ++i) {
      printf("%d %d\n", resL[i], resR[i]);
      tmp[i].l = tmpL[i];
      tmp[i].r = tmpR[i];
    }
    std::sort(tmp + 1, tmp + 1 + ans, cmp1);
    for (register int i = 1; i <= ans; ++i)
      pos1 = (tmp[i].l <= pos1
                  ? ((pos1) > (tmp[i].r + 1) ? (pos1) : (tmp[i].r + 1))
                  : pos1);
    std::sort(tmp + 1, tmp + 1 + ans, cmp2);
    for (register int i = 1; i <= ans; ++i)
      pos2 = (tmp[i].r >= pos2
                  ? ((pos2) < (tmp[i].l - 1) ? (pos2) : (tmp[i].l - 1))
                  : pos2);
    pos1 = ((pos1) > (1) ? (pos1) : (1));
    pos2 = ((pos2) < (len) ? (pos2) : (len));
    printf("%d %d\n", ask(1, 1, len, 1, pos1), ask(1, 1, len, 1, pos2));
  }
  return 0;
}