#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '{';
  string sep;
  for (const auto &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
const int ALPHABET = 26;
const char MIN_CHAR = 'a';
vector<int> eq_count;
int needed() {
  int maximum = 0, sum = 0;
  for (int c = 0; c < ALPHABET; c++) {
    maximum = max(maximum, eq_count[c]);
    sum += eq_count[c];
  }
  return max(maximum, (sum + 1) / 2) + 1;
}
void decrement(int x) { eq_count[x]--; }
void increment(int x) { eq_count[x]++; }
bool match(int x, int y) {
  if (x == y) return false;
  int before = needed();
  decrement(x);
  decrement(y);
  int after = needed();
  if (after == before - 1) return true;
  increment(x);
  increment(y);
  return false;
}
void run_case() {
  string S;
  cin >> S;
  for (char &c : S) c -= MIN_CHAR;
  int N = S.size();
  eq_count.assign(ALPHABET, 0);
  for (int i = 0; i < N - 1; i++)
    if (S[i] == S[i + 1]) eq_count[S[i]]++;
  vector<pair<int, int>> moves;
  vector<pair<int, char>> eq_stack;
  int removed = 0;
  for (int i = 0; i < N - 1; i++)
    if (S[i] == S[i + 1]) {
      if (!eq_stack.empty() && match(eq_stack.back().second, S[i])) {
        moves.emplace_back(eq_stack.back().first + 1, i + 1 - removed);
        eq_stack.pop_back();
        removed += moves.back().second - moves.back().first;
      } else {
        eq_stack.emplace_back(i - removed, S[i]);
      }
    }
  while (!eq_stack.empty()) {
    moves.emplace_back(eq_stack.back().first + 1, N - removed);
    removed += moves.back().second - moves.back().first;
    eq_stack.pop_back();
  }
  moves.emplace_back(0, N - removed);
  cout << moves.size() << '\n';
  for (pair<int, int> &move : moves)
    cout << move.first + 1 << ' ' << move.second << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tests;
  cin >> tests;
  while (tests-- > 0) run_case();
}
