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;
const int N = 2e5 + 5;
int T, n;
char s[N];
vector<pair<char, int> > vc, sta;
vector<pair<int, int> > pr;
struct Counter {
  int cnt[127], ccnt[N], mx;
  void init() {
    for (int i = 'a'; i <= 'z'; ++i) cnt[i] = 0;
    for (int i = 1; i <= mx; ++i) ccnt[i] = 0;
    mx = 0;
    ccnt[0] = 26;
  }
  void modify(int x, int v) {
    --ccnt[cnt[x]];
    ++ccnt[cnt[x] += v];
    if (ccnt[mx + 1]) ++mx;
    if (!ccnt[mx]) --mx;
  }
} ct;
int d[N << 2], tag[N << 2];
void build(int l, int r, int o) {
  d[o] = 0, tag[o] = 0;
  if (l < r) {
    const int mid = (l + r) / 2;
    build(l, mid, o << 1);
    build(mid + 1, r, o << 1 | 1);
  }
}
void pushdown(int o, int len) {
  if (tag[o]) {
    tag[o << 1] = tag[o << 1 | 1] = 1;
    tag[o] = 0;
    d[o << 1] = (len + 1) / 2, d[o << 1 | 1] = len / 2;
  }
}
void modify(int l, int r, int o, const int& L, const int& R) {
  if (L <= l && r <= R) {
    d[o] = r - l + 1, tag[o] = 1;
  } else {
    pushdown(o, r - l + 1);
    const int mid = (l + r) / 2;
    if (L <= mid) modify(l, mid, o << 1, L, R);
    if (mid < R) modify(mid + 1, r, o << 1 | 1, L, R);
    d[o] = d[o << 1] + d[o << 1 | 1];
  }
}
int query(int l, int r, int o, const int& L, const int& R) {
  if (L <= l && r <= R) return d[o];
  pushdown(o, r - l + 1);
  const int mid = (l + r) / 2;
  int res = 0;
  if (L <= mid) res = query(l, mid, o << 1, L, R);
  if (mid < R) res += query(mid + 1, r, o << 1 | 1, L, R);
  return res;
}
void work() {
  cin >> (s + 1), n = strlen(s + 1);
  pr.clear();
  vc.clear();
  ct.init();
  for (int i = 2; i <= n; ++i)
    if (s[i] == s[i - 1]) vc.emplace_back(s[i - 1], i - 1);
  for (auto it : vc) ct.modify(it.first, 1);
  sta.clear();
  int m = vc.size();
  for (auto it : vc)
    if (sta.empty() || it.first == sta.back().first)
      sta.emplace_back(it);
    else {
      int cf = sta.back().first, cs = it.first;
      ct.modify(cf, -1);
      ct.modify(cs, -1);
      if (ct.mx * 2 <= m - 2) {
        pr.emplace_back(sta.back().second + 1, it.second);
        sta.pop_back();
        m -= 2;
      } else {
        ct.modify(cf, 1);
        ct.modify(cs, 1);
        sta.emplace_back(it);
      }
    }
  vc = sta;
  sta.clear();
  bool flg = 2 * ct.mx > m;
  for (auto it : vc)
    if (sta.empty() || it.first == sta.back().first || flg)
      sta.emplace_back(it);
    else {
      int cf = sta.back().first, cs = it.first;
      ct.modify(cf, -1);
      ct.modify(cs, -1);
      pr.emplace_back(sta.back().second + 1, it.second);
      sta.pop_back();
      m -= 2;
      flg = 1;
    }
  vc = sta;
  sta.clear();
  for (auto it : vc) {
    if (sta.empty() || it.first == sta.back().first)
      sta.emplace_back(it);
    else {
      int cf = sta.back().first, cs = it.first;
      if (ct.cnt[cf] == ct.mx || ct.cnt[cs] == ct.mx) {
        ct.modify(cf, -1);
        ct.modify(cs, -1);
        pr.emplace_back(sta.back().second + 1, it.second);
        sta.pop_back();
        m -= 2;
      } else
        sta.emplace_back(it);
    }
  }
  sta.emplace_back(s[n], n);
  for (auto it : sta) pr.emplace_back(1, it.second);
  cout << pr.size() << '\n';
  build(1, n, 1);
  for (auto it : pr) {
    int l = it.first, r = it.second;
    if (l > 1) l -= query(1, n, 1, 1, l - 1);
    if (r > 1) r -= query(1, n, 1, 1, r - 1);
    cout << l << ' ' << r << '\n';
    modify(1, n, 1, it.first, it.second);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  for (cin >> T; T--;) work();
  return 0;
}