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>
template <typename Tp>
void read(Tp &res) {
  static char ch;
  ch = getchar(), res = 0;
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) res = res * (Tp)10 + (Tp)(ch - 48), ch = getchar();
}
const int MAXN = 2e5 + 19;
char s[MAXN];
int n;
struct Node {
  int ls, rs, sum;
  bool tag;
} tr[MAXN << 1];
int root, ind;
inline void push_up(int node) {
  tr[node].tag = tr[tr[node].ls].tag && tr[tr[node].rs].tag;
  tr[node].sum = tr[tr[node].ls].sum + tr[tr[node].rs].sum;
}
void modify(int &node, int L, int R, int l, int r) {
  if (!node)
    node = ++ind, tr[node].ls = tr[node].rs = tr[node].tag = tr[node].sum = 0;
  if (tr[node].tag) return;
  if (l <= L && R <= r)
    return void((tr[node].tag = 1, tr[node].sum = R - L + 1));
  int mid = (L + R) >> 1;
  if (l <= mid) modify(tr[node].ls, L, mid, l, r);
  if (r > mid) modify(tr[node].rs, mid + 1, R, l, r);
  push_up(node);
}
int query(int node, int L, int R, int l, int r) {
  if (!node) return 0;
  if (tr[node].tag) return std::min(R, r) - std::max(L, l) + 1;
  if (l <= L && R <= r) return tr[node].sum;
  int mid = (L + R) >> 1, res = 0;
  if (l <= mid) res += query(tr[node].ls, L, mid, l, r);
  if (r > mid) res += query(tr[node].rs, mid + 1, R, l, r);
  return res;
}
char t[MAXN];
int pos[MAXN], len;
int ma, cnt[26];
std::vector<std::pair<int, int> > ans;
inline void del(int l, int r) {
  ans.push_back(std::make_pair(l + 1 - query(root, 1, n, 1, l),
                               r - query(root, 1, n, 1, r - 1)));
  modify(root, 1, n, l + 1, r);
}
int st[MAXN], top;
void solve1(void) {
  top = 0;
  for (int i = 1; i <= len; ++i)
    if (t[i] == ma) {
      if (top && t[st[top]] != ma)
        del(pos[st[top--]], pos[i]);
      else
        st[++top] = i;
    } else {
      if (top && t[st[top]] == ma)
        del(pos[st[top--]], pos[i]);
      else
        st[++top] = i;
    }
}
inline bool check(void) {
  int mx = 0, tot = 0;
  for (int i = 0; i < 26; ++i) tot += cnt[i], mx = std::max(mx, cnt[i]);
  return mx * 2 <= tot;
}
void solve2(void) {
  top = 0;
  if (len & 1) --cnt[t[len--] - 'a'];
  for (int i = 1; i <= len; ++i)
    if (!top)
      st[++top] = i;
    else {
      if (t[st[top]] == t[i]) {
        st[++top] = i;
        continue;
      }
      --cnt[t[i] - 'a'], --cnt[t[st[top]] - 'a'];
      if (!check())
        ++cnt[t[i] - 'a'], ++cnt[t[st[top]] - 'a'], st[++top] = i;
      else {
        del(pos[st[top--]], pos[i]);
      }
    }
}
int main() {
  int T;
  read(T);
  while (T--) {
    scanf("%s", s + 1), n = strlen(s + 1);
    root = ind = len = 0, ma = 'a';
    for (int i = 1; i < n; ++i)
      if (s[i] == s[i + 1]) t[++len] = s[i], pos[len] = i;
    for (int i = 0; i < 26; ++i) cnt[i] = 0;
    for (int i = 1; i <= len; ++i) ++cnt[t[i] - 'a'];
    for (int i = 0; i < 26; ++i) {
      if (cnt[i] > cnt[ma - 'a']) ma = i + 'a';
    }
    ans.clear();
    if (cnt[ma - 'a'] * 2 > len)
      solve1();
    else
      solve2();
    len = 0;
    for (int i = 1; i <= n; ++i)
      if (!query(root, 1, n, i, i)) t[++len] = s[i];
    t[len + 1] = '\0';
    int last = 0;
    for (int i = 1; i < len; ++i)
      if (t[i] == t[i + 1])
        ans.push_back(std::make_pair(1, i - last)), last = i;
    ans.push_back(std::make_pair(1, len - last));
    printf("%d\n", (int)ans.size());
    for (std::vector<std::pair<int, int> >::iterator it = ans.begin();
         it != ans.end(); ++it)
      printf("%d %d\n", it->first, it->second);
  }
  return 0;
}