#include <bits/stdc++.h>
using namespace std;
int T;
char s[200010];
int len;
struct opt {
  int ss;
  int id;
  opt(int ss_ = 0, int id_ = 0) : ss(ss_), id(id_) {}
} st[200010];
int tot;
int cnt[30];
struct seg_tree {
  int sum[200010 << 2];
  bool lz[200010 << 2];
  void build(int now, int l, int r) {
    lz[now] = 0;
    sum[now] = r - l + 1;
    if (l == r) return;
    int mid = l + r >> 1;
    build(now << 1, l, mid);
    build(now << 1 | 1, mid + 1, r);
  }
  void gai(int now) {
    sum[now] = 0;
    lz[now] = 1;
  }
  void pushdown(int now) {
    if (!lz[now]) return;
    gai(now << 1), gai(now << 1 | 1);
    lz[now] = 0;
  }
  void modify(int now, int l, int r, int ll, int rr) {
    if (ll <= l && r <= rr) return void(gai(now));
    pushdown(now);
    int mid = l + r >> 1;
    if (ll <= mid) modify(now << 1, l, mid, ll, rr);
    if (rr >= mid + 1) modify(now << 1 | 1, mid + 1, r, ll, rr);
    sum[now] = sum[now << 1] + sum[now << 1 | 1];
  }
  int query(int now, int l, int r, int ll, int rr) {
    if (ll <= l && r <= rr) return sum[now];
    pushdown(now);
    int mid = l + r >> 1;
    int u = 0;
    if (ll <= mid) u += query(now << 1, l, mid, ll, rr);
    if (rr >= mid + 1) u += query(now << 1 | 1, mid + 1, r, ll, rr);
    return u;
  }
} S;
pair<int, int> ans[200010];
int num;
opt zhan[200010];
int gg;
int sum;
void upd(opt a, opt b) {
  ans[++num] =
      make_pair(S.query(1, 1, len, 1, a.id), S.query(1, 1, len, 1, b.id - 1));
  S.modify(1, 1, len, a.id, b.id - 1);
  cnt[a.ss]--, cnt[b.ss]--;
  sum -= 2;
}
void solve() {
  sum = tot;
  for (int i = 1; i <= tot; i++) cnt[st[i].ss]++;
  int ty = -1;
  for (int i = 0; i < 26; i++)
    if (cnt[i] >= ((sum + 1) >> 1)) ty = i;
  for (int i = 1; i <= tot; i++) {
    if (!gg)
      zhan[++gg] = st[i];
    else {
      if (zhan[gg].ss != st[i].ss) {
        if (zhan[gg].ss == ty || st[i].ss == ty || ty == -1) {
          upd(zhan[gg], st[i]);
          gg--;
          if (ty == -1) {
            for (int i = 0; i < 26; i++)
              if (cnt[i] >= ((sum + 1) >> 1)) ty = i;
          }
        } else
          zhan[++gg] = st[i];
      } else
        zhan[++gg] = st[i];
    }
  }
  for (int i = 1; i < gg; i++) {
    ans[++num] = make_pair(S.query(1, 1, len, 1, zhan[i].id),
                           S.query(1, 1, len, 1, zhan[i + 1].id - 1));
    S.modify(1, 1, len, zhan[i].id, zhan[i + 1].id - 1);
  }
  if (gg) {
    ans[++num] = make_pair(S.query(1, 1, len, 1, zhan[gg].id),
                           S.query(1, 1, len, 1, len));
    S.modify(1, 1, len, zhan[gg].id, len);
  }
  ans[++num] = make_pair(1, S.query(1, 1, len, 1, len));
}
int main() {
  cin >> T;
  while (T--) {
    num = 0;
    gg = 0;
    memset(cnt, 0, sizeof(cnt));
    tot = 0;
    scanf("%s", &s[1]);
    len = strlen(&s[1]);
    S.build(1, 1, len);
    for (int i = 2; i <= len; i++)
      if (s[i - 1] == s[i]) st[++tot] = opt(s[i] - 'a', i);
    solve();
    cout << num << '\n';
    for (int i = 1; i <= num; i++)
      cout << ans[i].first << " " << ans[i].second << '\n';
  }
  return 0;
}
