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;
template <typename T>
bool chkmax(T &x, T y) {
  return x < y ? x = y, true : false;
}
template <typename T>
bool chkmin(T &x, T y) {
  return x > y ? x = y, true : false;
}
int readint() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
struct node {
  int lazy, sum;
} t[600000];
int n;
int cnt[26];
char s[200005];
set<pair<int, int> > s1;
set<pair<int, int> > s2[26];
vector<pair<int, int> > ans;
void build(int id, int l, int r) {
  t[id].sum = t[id].lazy = 0;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(id << 1, l, mid);
  build(id << 1 | 1, mid + 1, r);
}
void pushdown(int id, int l, int r) {
  if (t[id].lazy) {
    int mid = (l + r) / 2;
    t[id << 1].sum = mid - l + 1, t[id << 1].lazy = t[id].lazy;
    t[id << 1 | 1].sum = r - mid, t[id << 1 | 1].lazy = t[id].lazy;
    t[id].lazy = 0;
  }
}
void change(int id, int l, int r, int ql, int qr) {
  if (l == ql && r == qr) return (void)(t[id].sum = r - l + 1, t[id].lazy = 1);
  pushdown(id, l, r);
  int mid = (l + r) / 2;
  if (qr <= mid)
    change(id << 1, l, mid, ql, qr);
  else if (ql > mid)
    change(id << 1 | 1, mid + 1, r, ql, qr);
  else
    change(id << 1, l, mid, ql, mid),
        change(id << 1 | 1, mid + 1, r, mid + 1, qr);
  t[id].sum = t[id << 1].sum + t[id << 1 | 1].sum;
}
int query(int id, int l, int r, int ql, int qr) {
  if (l == ql && r == qr) return t[id].sum;
  pushdown(id, l, r);
  int mid = (l + r) / 2;
  if (qr <= mid)
    return query(id << 1, l, mid, ql, qr);
  else if (ql > mid)
    return query(id << 1 | 1, mid + 1, r, ql, qr);
  else
    return query(id << 1, l, mid, ql, mid) +
           query(id << 1 | 1, mid + 1, r, mid + 1, qr);
}
int main() {
  int T = readint();
  while (T--) {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    build(1, 1, n);
    for (int i = 0; i < 26; i++) s2[i].clear(), cnt[i] = 0;
    s1.clear();
    for (int i = 1; i < n; i++)
      if (s[i] == s[i + 1])
        s1.insert(make_pair(i, s[i] - 'a')), cnt[s[i] - 'a']++;
    for (auto it1 = s1.begin(); it1 != s1.end(); it1++) {
      auto it2 = it1;
      it2++;
      if (it2 == s1.end()) break;
      if (it1->second == it2->second) continue;
      s2[it1->second].insert(make_pair(it1->first, it2->first));
      s2[it2->second].insert(make_pair(it1->first, it2->first));
    }
    ans.clear();
    while (1) {
      int maxa = 0, opt = -1;
      for (int i = 0; i < 26; i++)
        if (chkmax(maxa, cnt[i])) opt = i;
      if (opt < 0) break;
      if (s2[opt].size() == 0) {
        for (auto x : s1) {
          int tmp = x.first - query(1, 1, n, 1, x.first);
          ans.push_back(make_pair(tmp, tmp));
          change(1, 1, n, x.first, x.first);
        }
        break;
      }
      pair<int, int> x = *s2[opt].begin();
      s2[opt].erase(x);
      if (s[x.first] - 'a' == opt)
        s2[s[x.second] - 'a'].erase(x);
      else
        s2[s[x.first] - 'a'].erase(x);
      ans.push_back(make_pair(x.first + 1 - query(1, 1, n, 1, x.first),
                              x.second - query(1, 1, n, 1, x.second - 1)));
      change(1, 1, n, x.first + 1, x.second);
      auto it1 = s1.lower_bound(make_pair(x.first, -1)),
           it2 = s1.lower_bound(make_pair(x.second, -1));
      cnt[s[x.first] - 'a']--, cnt[s[x.second] - 'a']--;
      if (it1 != s1.begin()) {
        auto it3 = it1, it4 = it2;
        it3--, it4++;
        if (it3->second != it1->second) {
          s2[it3->second].erase(make_pair(it3->first, it1->first));
          s2[it1->second].erase(make_pair(it3->first, it1->first));
        }
        if (it4 != s1.end()) {
          if (it2->second != it4->second) {
            s2[it4->second].erase(make_pair(it2->first, it4->first));
            s2[it2->second].erase(make_pair(it2->first, it4->first));
          }
          if (it3->second != it4->second) {
            s2[it3->second].insert(make_pair(it3->first, it4->first));
            s2[it4->second].insert(make_pair(it3->first, it4->first));
          }
        }
      } else {
        auto it4 = it2;
        it4++;
        if (it4 != s1.end() && it2->second != it4->second) {
          s2[it4->second].erase(make_pair(it2->first, it4->first));
          s2[it2->second].erase(make_pair(it2->first, it4->first));
        }
      }
      s1.erase(it1), s1.erase(it2);
    }
    ans.push_back(make_pair(1, n - query(1, 1, n, 1, n)));
    printf("%d\n", ans.size());
    for (auto x : ans) printf("%d %d\n", x.first, x.second);
  }
  return 0;
}