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';
int N;
string S;
vector<int> eq_freq;
fenwick_tree<int> tree;
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 - MIN_CHAR]--;
  eq_freq[y - MIN_CHAR]--;
  int after = needed();
  eq_freq[x - MIN_CHAR]++;
  eq_freq[y - MIN_CHAR]++;
  return after == before - 1;
}
void run_case() {
  cin >> S;
  N = S.size();
  tree.init(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);
    while (true) {
      int x = tree.find_last_prefix(under_start);
      if (x >= end) break;
      tree.update(x, -1);
    }
  };
  eq_freq.assign(ALPHABET, 0);
  vector<pair<int, int>> eq_vec;
  for (int i = 0; i < N - 1; i++)
    if (S[i] == S[i + 1]) {
      eq_vec.emplace_back(i, i + 1);
      eq_freq[S[i] - MIN_CHAR]++;
    }
  vector<pair<int, int>> eq_stack;
  for (pair<int, int> &eq : eq_vec)
    if (!eq_stack.empty() && can_match(S[eq_stack.back().first], S[eq.first])) {
      eq_freq[S[eq_stack.back().first] - MIN_CHAR]--;
      eq_freq[S[eq.first] - MIN_CHAR]--;
      add_move(eq_stack.back().second, eq.first + 1);
      eq_stack.pop_back();
    } else {
      eq_stack.push_back(eq);
    }
  while (!eq_stack.empty()) {
    add_move(eq_stack.back().second, 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();
}