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;
namespace Fread {
const int MAXN = 1 << 20;
char buf[MAXN], *S, *T;
inline char getchar() {
  if (S == T) {
    T = (S = buf) + fread(buf, 1, MAXN, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
}  // namespace Fread
namespace Fwrite {
const int MAXN = 1 << 20;
char buf[MAXN], *S = buf, *T = buf + MAXN;
inline void flush() {
  fwrite(buf, 1, S - buf, stdout);
  S = buf;
}
inline void putchar(char c) {
  *S++ = c;
  if (S == T) flush();
}
struct _ {
  ~_() { flush(); }
} __;
}  // namespace Fwrite
template <typename T>
inline void read(T& x) {
  x = 0;
  int f = 1;
  char ch = Fread::getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = Fread::getchar();
  }
  while (isdigit(ch))
    x = (x << 3) + (x << 1) + (ch ^ '0'), ch = Fread::getchar();
  x *= f;
}
template <typename T>
inline void write(T x, bool _enter = 0, bool _space = 0) {
  if (!x)
    Fwrite::putchar('0');
  else {
    if (x < 0) Fwrite::putchar('-'), x = -x;
    static char dig[41];
    int top = 0;
    while (x) dig[++top] = (x % 10) ^ '0', x /= 10;
    while (top) Fwrite::putchar(dig[top--]);
  }
  if (_enter) Fwrite::putchar('\n');
  if (_space) Fwrite::putchar(' ');
}
namespace Fastio {
struct reader {
  template <typename T>
  reader& operator>>(T& x) {
    ::read(x);
    return *this;
  }
  reader& operator>>(char& c) {
    c = Fread::getchar();
    while (c == '\n' || c == ' ') c = Fread::getchar();
    return *this;
  }
  reader& operator>>(char* str) {
    int len = 0;
    char ch = Fread::getchar();
    while (ch != '\n' && ch != ' ') str[len++] = ch, ch = Fread::getchar();
    str[len] = '\0';
    return *this;
  }
  reader& operator>>(std::string& s) {
    std::cin >> s;
    return *this;
  }
} cin;
const char endl = '\n';
struct writer {
  template <typename T>
  writer& operator<<(T x) {
    ::write(x, 0, 0);
    return *this;
  }
  writer& operator<<(char c) {
    Fwrite::putchar(c);
    return *this;
  }
  writer& operator<<(const char* str) {
    int cur = 0;
    while (str[cur]) Fwrite::putchar(str[cur++]);
    return *this;
  }
} cout;
}  // namespace Fastio
const int MAXN = 2e5;
int n, m, a[MAXN + 5], p[MAXN + 5], cnt[26], top;
pair<int, int> sta[MAXN + 5];
char s[MAXN + 5];
bool check() {
  int mx = 0, sum = cnt[0];
  for (int i = 1; i < 26; ++i) {
    sum += cnt[i];
    if (cnt[i] > cnt[mx]) mx = i;
  }
  return 2 * cnt[mx] < sum;
}
int main() {
  int T;
  Fastio::cin >> T;
  while (T--) {
    Fastio::cin >> (s + 1);
    n = strlen(s + 1);
    m = 0;
    for (int i = 2; i <= n; ++i)
      if (s[i] == s[i - 1]) a[++m] = s[i] - 'a', p[m] = i;
    int sum = n;
    for (int i = 0; i < 26; ++i) cnt[i] = 0;
    for (int i = 1; i <= m; ++i) cnt[a[i]]++;
    vector<pair<int, int> > ans;
    top = 0;
    for (int i = 1, lazy = 0; i <= m; ++i) {
      if (!check() || !top || sta[top].first == a[i])
        sta[++top] = make_pair(a[i], p[i] - lazy);
      else {
        ans.push_back(make_pair(sta[top].second, p[i] - 1 - lazy));
        sum -= (p[i] - 1 - lazy) - sta[top].second + 1;
        lazy += (p[i] - 1 - lazy) - sta[top].second + 1;
        cnt[sta[top].first]--;
        cnt[a[i]]--;
        top--;
      }
    }
    if (sum) {
      m = top;
      top = 0;
      for (int i = 1; i <= m; ++i) a[i] = sta[i].first, p[i] = sta[i].second;
      int mx = 0;
      for (int i = 1; i < 26; ++i)
        if (cnt[i] > cnt[mx]) mx = i;
      for (int i = 1, lazy = 0; i <= m; ++i) {
        if (top && (a[i] == mx) + (sta[top].first == mx) == 1) {
          ans.push_back(make_pair(sta[top].second, p[i] - 1 - lazy));
          sum -= (p[i] - 1 - lazy) - sta[top].second + 1;
          lazy += (p[i] - 1 - lazy) - sta[top].second + 1;
          top--;
        } else {
          sta[++top] = make_pair(a[i], p[i] - lazy);
        }
      }
      for (int i = 1, lazy = 0; i <= top; ++i) {
        assert(sta[i].first == mx);
        ans.push_back(make_pair(sta[i].second - lazy, sta[i].second - lazy));
        sum--;
        lazy++;
      }
      if (sum > 0) {
        ans.push_back(make_pair(1, sum));
      }
    }
    Fastio::cout << ((int)(ans).size()) << Fastio::endl;
    for (int i = 0; i < ((int)(ans).size()); ++i)
      Fastio::cout << ans[i].first << " " << ans[i].second << Fastio::endl;
  }
  return 0;
}