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 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...);
}
template <typename T>
struct fenwick_tree {
  int tree_n = 0;
  T tree_sum = 0;
  vector<T> tree;
  fenwick_tree(int n = -1) {
    if (n >= 0) init(n);
  }
  void init(int n) {
    tree_n = n;
    tree_sum = 0;
    tree.assign(tree_n + 1, 0);
  }
  template <typename T_array>
  void build(const T_array &initial) {
    assert((int)initial.size() == tree_n);
    tree_sum = 0;
    for (int i = 1; i <= tree_n; i++) {
      tree[i] = initial[i - 1];
      tree_sum += initial[i - 1];
      for (int k = (i & -i) >> 1; k > 0; k >>= 1) tree[i] += tree[i - k];
    }
  }
  void update(int index, const T &change) {
    assert(0 <= index && index < tree_n);
    tree_sum += change;
    for (int i = index + 1; i <= tree_n; i += i & -i) tree[i] += change;
  }
  T query(int count) const {
    assert(count <= tree_n);
    T sum = 0;
    for (int i = count; i > 0; i -= i & -i) sum += tree[i];
    return sum;
  }
  T query_suffix(int start) const { return tree_sum - query(start); }
  T query(int a, int b) const { return query(b) - query(a); }
  T get(int a) const {
    assert(0 <= a && a < tree_n);
    int above = a + 1;
    T sum = tree[above];
    above -= above & -above;
    while (a != above) {
      sum -= tree[a];
      a -= a & -a;
    }
    return sum;
  }
  bool set(int index, T value) {
    assert(0 <= index && index < tree_n);
    T current = get(index);
    if (current == value) return false;
    update(index, value - current);
    return true;
  }
  int find_last_prefix(T sum) const {
    if (sum < 0) return -1;
    int prefix = 0;
    for (int k = 31 - __builtin_clz(tree_n); k >= 0; k--)
      if (prefix + (1 << k) <= tree_n && tree[prefix + (1 << k)] <= sum) {
        prefix += 1 << k;
        sum -= tree[prefix];
      }
    return prefix;
  }
};
const int ALPHABET = 26;
const char MIN_CHAR = 'a';
vector<int> eq_freq;
int needed() {
  int maximum = 0, sum = 0;
  for (int c = 0; c < ALPHABET; c++) {
    maximum = max(maximum, eq_freq[c]);
    sum += eq_freq[c];
  }
  return max(maximum, (sum + 1) / 2) + 1;
}
bool can_match(char x, char y) {
  if (x == y) return false;
  int before = needed();
  eq_freq[x]--;
  eq_freq[y]--;
  int after = needed();
  eq_freq[x]++;
  eq_freq[y]++;
  return after == before - 1;
}
void run_case() {
  string S;
  cin >> S;
  for (char &c : S) c -= MIN_CHAR;
  int N = S.size();
  fenwick_tree<int> tree(N);
  tree.build(vector<int>(N, 1));
  vector<pair<int, int>> moves;
  auto &&add_move = [&](int start, int end) {
    int under_start = tree.query(start);
    int under_end = tree.query(end);
    moves.emplace_back(under_start, under_end);
    for (int i = 0; i < under_end - under_start; i++) {
      int index = tree.find_last_prefix(under_start);
      tree.update(index, -1);
    }
  };
  eq_freq.assign(ALPHABET, 0);
  vector<int> eq_pos;
  for (int i = 0; i < N - 1; i++)
    if (S[i] == S[i + 1]) {
      eq_pos.push_back(i);
      eq_freq[S[i]]++;
    }
  vector<int> eq_stack;
  for (int &eq : eq_pos)
    if (!eq_stack.empty() && can_match(S[eq_stack.back()], S[eq])) {
      eq_freq[S[eq_stack.back()]]--;
      eq_freq[S[eq]]--;
      add_move(eq_stack.back() + 1, eq + 1);
      eq_stack.pop_back();
    } else {
      eq_stack.push_back(eq);
    }
  while (!eq_stack.empty()) {
    add_move(eq_stack.back() + 1, N);
    eq_stack.pop_back();
  }
  add_move(0, N);
  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();
}