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 T1, typename T2>
ostream& operator<<(ostream& output, const pair<T1, T2>& p) {
  output << "(" << p.first << "," << p.second << ")";
  return output;
}
template <typename T>
ostream& operator<<(ostream& output, const vector<T>& v) {
  unsigned int i;
  bool f = 1;
  for (i = 0; i < v.size(); i++) {
    if (!f) output << " ";
    output << v[i];
    f = 0;
  }
  return output;
}
template <typename T>
ostream& operator<<(ostream& output, const list<T>& l) {
  typename list<T>::const_iterator it;
  bool f = 1;
  for (it = l.begin(); it != l.end(); it++) {
    if (!f) output << " ";
    output << *it;
    f = 0;
  }
  return output;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& output, const map<T1, T2>& m) {
  typename map<T1, T2>::const_iterator it;
  bool f = 1;
  for (it = m.begin(); it != m.end(); it++) {
    if (!f) output << " ";
    output << "(" << it->first << " -> " << it->second << ")";
    f = 0;
  }
  return output;
}
template <typename T>
ostream& operator<<(ostream& output, const set<T>& s) {
  typename set<T>::const_iterator it;
  bool f = 1;
  for (it = s.begin(); it != s.end(); it++) {
    if (!f) output << " ";
    output << *it;
    f = 0;
  }
  return output;
}
char s[200001];
int l[200000], r[200000];
vector<pair<int, int> > ans;
set<pair<int, char> > S;
int occ[26];
vector<int> Q[26], Q2[26];
int getAns(int s, int e) {
  if (s > e) return 0;
  int i = s;
  if (r[s] == s) {
    getAns(s + 1, e);
    ans.push_back(make_pair(s, s));
    return 0;
  }
  vector<int> v;
  while ((r[i] != -1) && (r[i] > i)) v.push_back(i), i = r[i];
  v.push_back(i);
  for (i = 1; i < v.size(); i++) getAns(v[i - 1] + 1, v[i] - 1);
  getAns(v.back() + 1, e);
  ans.push_back(make_pair(v[0], v.back()));
  return 0;
}
int bit[200001];
set<int> sad;
int main() {
  int i;
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%s", s);
    int n = strlen(s);
    for (i = 0; i < n; i++)
      r[i] = (i == n - 1) ? -1 : i + 1, l[i] = (i == 0) ? -1 : i - 1;
    fill(occ, occ + 26, 0);
    for (i = 0; i < n - 1; i++) {
      if (s[i] == s[i + 1]) S.insert(make_pair(i, s[i])), occ[s[i] - 'a']++;
    }
    S;
    for (auto it = S.begin(); it != S.end(); it++) {
      auto it2 = it;
      it2++;
      if ((it2 != S.end()) && (it->second != it2->second)) {
        Q[it->second - 'a'].push_back(it->first);
        Q2[it2->second - 'a'].push_back(it2->first);
      }
    }
    while (1) {
      int mi = -1;
      for (i = 0; i < 26; i++) {
        if (occ[i] == 0) continue;
        if ((mi == -1) || (occ[i] > occ[mi])) mi = i;
      }
      if (mi == -1) break;
      ;
      S;
      while (!Q[mi].empty()) {
        "here";
        auto it = S.lower_bound(make_pair(Q[mi].back(), '\0'));
        if ((it == S.end()) || (it == --S.end()) ||
            (*it != make_pair(Q[mi].back(), s[Q[mi].back()])))
          Q[mi].pop_back();
        else {
          auto it2 = it;
          it2++;
          if (it->second == it2->second)
            Q[mi].pop_back();
          else
            break;
        }
      }
      while (!Q2[mi].empty()) {
        auto it = S.lower_bound(make_pair(Q2[mi].back(), '\0'));
        if ((it == S.end()) || (it == S.begin()) ||
            (*it != make_pair(Q2[mi].back(), s[Q2[mi].back()])))
          Q2[mi].pop_back();
        else {
          auto it2 = it;
          it2--;
          if (it->second == it2->second)
            Q2[mi].pop_back();
          else
            break;
        }
      }
      if (!Q[mi].empty()) {
        int u = Q[mi].back();
        ;
        Q[mi].pop_back();
        auto it = S.lower_bound(make_pair(u, '\0'));
        auto it2 = it;
        it2++;
        int a = it->first, b = it2->first, c = r[b];
        ;
        ;
        ;
        l[r[a]] = r[b] = -1;
        l[c] = a, r[a] = c;
        assert(it->second != it2->second);
        occ[it->second - 'a']--, occ[it2->second - 'a']--;
        S.erase(it), it2 = S.erase(it2);
        it = it2;
        if ((it != S.begin()) && (it2 != S.end())) {
          it--;
          if (it->second != it2->second) {
            Q[it->second - 'a'].push_back(it->first);
            Q2[it2->second - 'a'].push_back(it2->first);
          }
        }
      } else if (!Q2[mi].empty()) {
        int u = Q2[mi].back();
        ;
        Q2[mi].pop_back();
        auto it = S.lower_bound(make_pair(u, '\0'));
        auto it2 = it;
        it--;
        int a = it->first, b = it2->first, c = r[b];
        l[r[a]] = r[b] = -1;
        l[c] = a, r[a] = c;
        assert(it->second != it2->second);
        occ[it->second - 'a']--, occ[it2->second - 'a']--;
        S.erase(it), it2 = S.erase(it2);
        it = it2;
        if ((it != S.begin()) && (it2 != S.end())) {
          it--;
          if (it->second != it2->second) {
            Q[it->second - 'a'].push_back(it->first);
            Q2[it2->second - 'a'].push_back(it2->first);
          }
        }
      } else
        break;
    }
    int c = 0;
    char z;
    for (i = 0; i < 26; i++) {
      if (occ[i] > 0) c++, z = i + 'a';
    }
    assert(c <= 1);
    for (auto it = S.begin(); it != S.end(); it++) {
      int u = it->first, v = r[it->first];
      assert(it->second == z);
      r[u] = l[v] = -1;
    };
    ;
    getAns(0, n - 1);
    printf("%d\n", ans.size());
    int j;
    fill(bit, bit + n + 1, 0);
    for (i = 0; i < n; i++) {
      for (j = i + 1; j <= n; j += j & (-j)) bit[j]++;
    }
    for (i = 0; i < n; i++) sad.insert(i);
    for (i = 0; i < ans.size(); i++) {
      int s = 0, e = 0;
      for (j = ans[i].first + 1; j > 0; j -= j & (-j)) s += bit[j];
      for (j = ans[i].second + 1; j > 0; j -= j & (-j)) e += bit[j];
      auto soclose = sad.lower_bound(ans[i].first);
      while ((soclose != sad.end()) && (*soclose <= ans[i].second)) {
        int iamsodumb = *soclose;
        for (j = iamsodumb + 1; j <= n; j += j & (-j)) bit[j]--;
        soclose = sad.erase(soclose);
      }
      printf("%d %d\n", s, e);
    }
    for (i = 0; i < 26; i++) {
      Q[i].clear();
      Q2[i].clear();
    }
    S.clear();
    ans.clear();
  }
  return 0;
}