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 oo = 2139063143;
const int N = 1010000;
const int P = 1000000007;
const double eps = 1e-7;
template <typename T>
inline void sc(T &x) {
  x = 0;
  static int p;
  p = 1;
  static char c;
  c = getchar();
  while (!isdigit(c)) {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c - 48);
    c = getchar();
  }
  x *= p;
}
template <typename T>
inline void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
inline void pr(T x) {
  print(x), putchar('\n');
}
template <typename T1, typename T2>
void chkmax(T1 &A, T2 B) {
  A = A >= B ? A : B;
}
template <typename T1, typename T2>
void chkmin(T1 &A, T2 B) {
  A = A <= B ? A : B;
}
struct TREE {
  int w, d;
} t[N << 2];
void build(int p, int l, int r) {
  t[p].w = t[p].d = 0;
  if (l == r) return;
  int mid = (l + r) >> 1, ls = p << 1, rs = ls | 1;
  build(ls, l, mid), build(rs, mid + 1, r);
}
void pushd(int p, int l, int r) { t[p].d = 1, t[p].w = r - l + 1; }
void push(int p, int l, int r) {
  if (t[p].d) {
    int mid = (l + r) >> 1, ls = p << 1, rs = ls | 1;
    pushd(ls, l, mid), pushd(rs, mid + 1, r);
    t[p].d = 0;
  }
}
void change(int p, int l, int r, int L, int R) {
  if (L <= l && r <= R) return pushd(p, l, r), void();
  int mid = (l + r) >> 1, ls = p << 1, rs = ls | 1;
  push(p, l, r);
  if (L <= mid) change(ls, l, mid, L, R);
  if (R > mid) change(rs, mid + 1, r, L, R);
  t[p].w = t[ls].w + t[rs].w;
}
int query(int p, int l, int r, int L, int R) {
  if (L <= l && r <= R) return t[p].w;
  if (L > R || l > R || L > r) return 0;
  int mid = (l + r) >> 1, ls = p << 1, rs = ls | 1, ans = 0;
  push(p, l, r);
  if (L <= mid) ans = query(ls, l, mid, L, R);
  if (R > mid) ans += query(rs, mid + 1, r, L, R);
  return ans;
}
int n, m, k;
int a[N], b[N], c[N], cnt[30], st[N], z = 0;
int ans[N][2];
void del(int l, int r) {
  ans[++k][0] = l - query(1, 1, n, 1, l - 1);
  ans[k][1] = r - query(1, 1, n, 1, r);
  change(1, 1, n, l, r);
}
int getma() {
  int p = 1;
  for (int i = 2; i <= 26; i++)
    if (cnt[i] > cnt[p]) p = i;
  return p;
}
bool check(int x, int y) {
  --cnt[x], --cnt[y], cnt[0] -= 2;
  int p = getma();
  if (cnt[p] * 2 > cnt[0]) return ++cnt[x], ++cnt[y], cnt[0] += 2, 0;
  return 1;
}
char s[N];
int main() {
  int T;
  sc(T);
  while (T--) {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    for (int i = 1; i <= n; i++) a[i] = s[i] - 'a' + 1;
    m = 0, k = 0;
    for (int i = 1; i < n; i++)
      if (a[i] == a[i + 1]) b[++m] = i, c[m] = a[i];
    build(1, 1, n);
    memset(cnt, 0, sizeof(cnt));
    for (int i = 1; i <= m; i++) ++cnt[c[i]];
    cnt[0] = m;
    int p = getma();
    z = 0;
    if (cnt[p] * 2 > m) {
      for (int i = 1; i <= m; i++) {
        if (z && (c[st[z]] == p) + (c[i] == p) == 1) {
          del(b[st[z]] + 1, b[i]), --z;
        } else
          st[++z] = i;
      }
      for (int i = 1; i < z; i++) del(b[st[i]] + 1, b[st[i + 1]]);
      if (z & 1)
        del(1, b[st[z]]), del(b[st[z]] + 1, n);
      else
        del(b[st[z]], n), del(1, n);
    } else {
      if (m & 1) del(b[m] + 1, n), --cnt[c[m]], --m;
      for (int i = 1; i <= m; i++) {
        if (z && c[st[z]] != c[i] && check(c[st[z]], c[i])) {
          del(b[st[z]] + 1, b[i]), --z;
        } else
          st[++z] = i;
      }
      del(1, n);
    }
    pr(k);
    for (int i = 1; i <= k; i++) printf("%d %d\n", ans[i][0], ans[i][1]);
  }
  return 0;
}