#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int T, n, cnt[30], stk[N], top, val[N];
char s[N];
int a[N];
int main() {
  ios::sync_with_stdio(false);
  cin >> T;
  while (T--) {
    cin >> (s + 1);
    n = strlen(s + 1);
    int tmp = 0, mx = 0, cur = 0;
    top = 0;
    for (int i = 0; i < 30; i++) cnt[i] = 0;
    for (int i = 1; i <= n; i++) {
      val[i] = s[i] - 'a';
      if (i > 1 && s[i] == s[i - 1]) ++tmp, ++cnt[val[i]];
    }
    for (int i = 0; i < 26; i++) mx = max(mx, cnt[i]);
    cout << max((tmp + 1) / 2, mx) + 1 << endl;
    for (int i = 1; i <= n; i++) {
      a[++cur] = val[i];
      if (cur < 2 || a[cur] != a[cur - 1]) continue;
      if (a[cur] == a[stk[top]] || !top) {
        stk[++top] = cur;
        continue;
      }
      mx = 0;
      for (int j = 0; j < 26; j++)
        if (cnt[j] > cnt[mx]) mx = j;
      if (cnt[mx] * 2 < tmp || mx == a[cur] || mx == a[stk[top]]) {
        tmp -= 2;
        --cnt[a[cur]];
        --cnt[a[stk[top]]];
        cout << stk[top] << ' ' << cur - 1 << endl;
        a[stk[top]] = a[cur];
        cur = stk[top--];
      } else
        stk[++top] = cur;
    }
    for (int i = cur, lst = cur; i > 0; --i) {
      if (i == 1 || a[i - 1] == a[i])
        cout << i << ' ' << lst << endl, lst = i - 1;
    }
  }
  return 0;
}
