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 T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
  bool done_something = false;
  stringstream res;
  res << "[";
  for (; begin_iter != end_iter and counter; ++begin_iter) {
    done_something = true;
    counter--;
    res << *begin_iter << ", ";
  }
  string str = res.str();
  if (done_something) {
    str.pop_back();
    str.pop_back();
  }
  str += "]";
  return str;
}
vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
  vector<int> ord(size);
  for (int i = 0; i < size; i++) ord[i] = i;
  sort(ord.begin(), ord.end(), compare);
  return ord;
}
template <typename T>
bool MinPlace(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool MaxPlace(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T>& p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  for (int i = 0; i < (int)v.size(); i++) {
    out << v[i];
    if (i != (int)v.size() - 1) out << ", ";
  }
  out << "]";
  return out;
}
template <class TH>
void _dbg(const char* name, TH val) {
  clog << name << ": " << val << endl;
}
template <class TH, class... TA>
void _dbg(const char* names, TH curr_val, TA... vals) {
  while (*names != ',') clog << *names++;
  clog << ": " << curr_val << ", ";
  _dbg(names + 1, vals...);
}
bool flag[1 << 20];
int fen[1 << 20];
void deflag(int v) {
  if (flag[v]) {
    flag[v] = 0;
    fen[2 * v] = 0;
    fen[2 * v + 1] = 0;
    flag[2 * v] = 1;
    flag[2 * v + 1] = 1;
  }
}
void reset(int v, int l, int r, int a, int b) {
  if (r < a or b < l) return;
  if (a <= l and r <= b) {
    flag[v] = 1;
    fen[v] = 0;
    return;
  }
  deflag(v);
  int m = (l + r) / 2;
  reset(2 * v, l, m, a, b);
  reset(2 * v + 1, m + 1, r, a, b);
  fen[v] = fen[2 * v] + fen[2 * v + 1];
}
int get(int v, int l, int r, int a, int b) {
  if (r < a or b < l) return 0;
  if (a <= l and r <= b) return fen[v];
  deflag(v);
  int m = (l + r) / 2;
  return get(2 * v, l, m, a, b) + get(2 * v + 1, m + 1, r, a, b);
}
vector<pair<int, int>> ans;
void match(int x, int y) {
  y--;
  assert(x <= y);
  int l = get(1, 0, (1 << 19) - 1, 0, x);
  int r = get(1, 0, (1 << 19) - 1, 0, y);
  ans.push_back({l, r});
  reset(1, 0, (1 << 19) - 1, x, y);
}
vector<int> good[2][26];
void solve() {
  for (int i = 0; i < 26; i++) good[0][i].clear(), good[1][i].clear();
  ans.clear();
  string SS;
  cin >> SS;
  int N = SS.size();
  vector<int> S(N);
  for (int i = 0; i < N; i++) S[i] = SS[i] - 'a';
  for (int i = 0; i < N; i++) {
    int v = i + (1 << 19);
    while (v != 0) {
      fen[v]++;
      v /= 2;
    }
  }
  vector<int> cnt(26, 0);
  set<int> pos;
  vector<int> pos_vec;
  for (int i = 0; i < N - 1; i++) {
    if (S[i] == S[i + 1]) {
      pos.insert(i + 1);
      pos_vec.push_back(i + 1);
      cnt[S[i]]++;
    }
  }
  for (int i = 0; i < ((int)((pos_vec).size())) - 1; i++) {
    if (S[pos_vec[i]] != S[pos_vec[i + 1]]) {
      good[0][S[pos_vec[i]]].push_back(pos_vec[i]);
      good[1][S[pos_vec[i + 1]]].push_back(pos_vec[i + 1]);
    }
  }
  while (!pos.empty()) {
    int let = 0;
    for (int i = 1; i < 26; i++) {
      if (cnt[i] > cnt[let]) let = i;
    }
    if (!good[0][let].empty()) {
      int l = good[0][let].back();
      good[0][let].pop_back();
      if (!pos.count(l)) continue;
      auto it = pos.upper_bound(l);
      if (it == pos.end()) continue;
      int r = *it;
      if (S[l] == S[r]) continue;
      match(l, r);
      pos.erase(l);
      pos.erase(r);
      cnt[S[l]]--;
      cnt[S[r]]--;
      auto aft = pos.lower_bound(l);
      if (aft == pos.end() or aft == pos.begin()) continue;
      auto bef = prev(aft);
      int a = *bef, b = *aft;
      if (S[a] != S[b]) {
        good[0][S[a]].push_back(a);
        good[1][S[b]].push_back(b);
      }
    } else if (!good[1][let].empty()) {
      int r = good[1][let].back();
      good[1][let].pop_back();
      if (!pos.count(r)) continue;
      auto it = pos.lower_bound(r);
      if (it == pos.begin()) continue;
      int l = *prev(it);
      if (S[l] == S[r]) continue;
      match(l, r);
      pos.erase(l);
      pos.erase(r);
      cnt[S[l]]--;
      cnt[S[r]]--;
      auto aft = pos.lower_bound(l);
      if (aft == pos.end() or aft == pos.begin()) continue;
      auto bef = prev(aft);
      int a = *bef, b = *aft;
      if (S[a] != S[b]) {
        good[0][S[a]].push_back(a);
        good[1][S[b]].push_back(b);
      }
    } else {
      vector<int> pos_vec;
      for (auto x : pos) pos_vec.push_back(x);
      reverse(pos_vec.begin(), pos_vec.end());
      for (int x : pos_vec) match(x, N);
      break;
    }
  }
  ans.push_back({1, fen[1]});
  cout << ans.size() << "\n";
  for (auto pp : ans) {
    cout << pp.first << " " << pp.second << "\n";
  }
  for (int i = 0; i < min(2 * N, 1 << 18); i++) {
    int v = i + (1 << 19);
    while (v != 0) {
      fen[v] = 0, flag[v] = 0;
      v /= 2;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  for (int t = 0; t < T; t++) solve();
}