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 ch = getchar();
  int nega = 1;
  while (!isdigit(ch)) {
    if (ch == '-') nega = -1;
    ch = getchar();
  }
  int ans = 0;
  while (isdigit(ch)) {
    ans = ans * 10 + ch - 48;
    ch = getchar();
  }
  if (nega == -1) return -ans;
  return ans;
}
inline int add(int x, int y) {
  return x + y >= 998244353 ? x + y - 998244353 : x + y;
}
inline int add(int x, int y, int z) { return add(add(x, y), z); }
inline int sub(int x, int y) { return x - y < 0 ? x - y + 998244353 : x - y; }
inline int mul(int x, int y) { return 1LL * x * y % 998244353; }
inline int mul(int x, int y, int z) { return mul(mul(x, y), z); }
inline int sqr(int x) { return mul(x, x); }
struct Node {
  int l, r, lid, rid, c;
};
char s[200005];
set<pair<int, int> > a[26], b[26];
set<int> c[26];
Node d[200005];
vector<pair<int, int> > ans;
int t[200005], n, len, cnt;
int lowbit(int u) { return u & (-u); }
void update(int u, int v) {
  while (u <= n) t[u] += v, u += lowbit(u);
}
int query(int u) {
  int ans = 0;
  while (u) ans += t[u], u -= lowbit(u);
  return ans;
}
void solve(int l, int r) {
  int il = l - query(l), ir = r - query(r);
  len -= (ir - il + 1);
  ans.push_back(make_pair(il, ir));
  update(r + 1, ir - il + 1);
}
void insert(int l, int r) {
  if (d[l].c == d[r].c)
    b[d[l].c].insert(make_pair(l, r));
  else
    a[d[l].c].insert(make_pair(l, r)), a[d[r].c].insert(make_pair(l, r));
}
void erase(int l, int r) {
  a[d[l].c].erase(make_pair(l, r));
  a[d[r].c].erase(make_pair(l, r));
  b[d[l].c].erase(make_pair(l, r));
}
void del(int l, int r) {
  int L = d[l].l, R = d[r].r;
  if (L) erase(L, l);
  if (R) erase(r, R);
  d[L].r = R, d[R].l = L;
  if (L && R) insert(L, R);
}
void work() {
  for (int i = 0; i < 26; i++) a[i].clear(), b[i].clear(), c[i].clear();
  ans.clear();
  scanf("%s", s + 1);
  n = len = strlen(s + 1);
  for (int i = 1; i <= n; i++) t[i] = 0;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i + 1]) continue;
    cnt++;
    d[cnt].l = cnt - 1, d[cnt].r = cnt + 1;
    d[cnt].lid = i, d[cnt].rid = i + 1;
    d[cnt].c = s[i] - 'a';
    c[s[i] - 'a'].insert(cnt);
    if (cnt != 1) insert(cnt - 1, cnt);
  }
  d[1].l = d[cnt].r = 0;
  while (cnt) {
    int maxn = 0;
    for (int i = 0; i < 26; i++)
      if (c[i].size() > c[maxn].size()) maxn = i;
    if (a[maxn].size()) {
      pair<int, int> u = *a[maxn].begin();
      a[maxn].erase(u);
      c[d[u.first].c].erase(u.first);
      c[d[u.second].c].erase(u.second);
      if (d[u.first].c == maxn)
        a[d[u.second].c].erase(u);
      else
        a[d[u.first].c].erase(u);
      del(u.first, u.second);
      solve(d[u.first].rid, d[u.second].lid);
      cnt -= 2;
      continue;
    }
    if (b[maxn].size()) {
      pair<int, int> u = *b[maxn].begin();
      b[maxn].erase(u);
      c[maxn].erase(u.second);
      del(u.second, u.second);
      solve(d[u.first].rid, d[u.second].lid);
      cnt--;
      continue;
    }
    int u = *c[maxn].begin();
    c[maxn].erase(u);
    del(u, u);
    solve(d[u].lid, d[u].rid - 1);
    cnt--;
  }
  ans.push_back(make_pair(1, len));
  printf("%d\n", (int)ans.size());
  for (pair<int, int> i : ans) printf("%d %d\n", i.first, i.second);
}
signed main() {
  int T = read();
  while (T--) work();
  return 0;
}