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 MOD = 1000000007;
const int INF = 2e9;
const long long INFLL = 1e18;
const int MAX_N = 300000;
const int MAX_K = 30;
int T;
string str;
int N;
vector<pair<int, int> > vt;
priority_queue<pair<int, int> > pq;
bool chk[MAX_N + 1];
int cnt[MAX_K + 1];
vector<pair<int, int> > gp1[MAX_K + 1], gp2[MAX_K + 1];
vector<pair<int, int> > ans;
int tree[MAX_N + 1];
void Add(int x, int y) {
  while (x <= N) {
    tree[x] += y;
    x += (x & -x);
  }
}
int Sum(int x) {
  int ret = 0;
  while (x > 0) {
    ret += tree[x];
    x -= (x & -x);
  }
  return ret;
}
int prv[MAX_N + 1], nxt[MAX_N + 1];
int main() {
  scanf("%d", &T);
  while (T--) {
    cin >> str;
    N = (int)str.size();
    while (!ans.empty()) ans.pop_back();
    while (!vt.empty()) vt.pop_back();
    for (int i = 0; i < (int)str.size() - 1; i++) {
      if (str[i] == str[i + 1]) {
        vt.push_back({str[i] - 'a', i});
      }
    }
    while (!pq.empty()) pq.pop();
    for (int i = 0; i < MAX_K; i++) {
      cnt[i] = false;
      while (!gp1[i].empty()) gp1[i].pop_back();
      while (!gp2[i].empty()) gp2[i].pop_back();
    }
    for (int i = 0; i < vt.size(); i++) {
      prv[i] = i - 1;
      nxt[i] = i + 1;
    }
    for (int i = 0; i < (int)vt.size() - 1; i++) {
      if (vt[i].first == vt[i + 1].first) {
        gp2[vt[i].first].push_back({i, i + 1});
      } else {
        gp1[vt[i].first].push_back({i, i + 1});
        gp1[vt[i + 1].first].push_back({i, i + 1});
      }
    }
    for (int i = 0; i < (int)vt.size(); i++) {
      chk[i] = false;
      cnt[vt[i].first]++;
    }
    for (int i = 0; i < MAX_K; i++) {
      if (cnt[i] != 0) {
        pq.push({cnt[i], i});
      }
    }
    bool tf2 = false;
    while (!pq.empty()) {
      pair<int, int> p = pq.top();
      int now = pq.top().second;
      pq.pop();
      if (cnt[now] != p.first) continue;
      bool tf = false;
      while (!gp1[now].empty()) {
        pair<int, int> n = gp1[now].back();
        gp1[now].pop_back();
        if (!chk[n.first] && !chk[n.second]) {
          ans.push_back({n.first, n.second});
          chk[n.first] = true;
          chk[n.second] = true;
          cnt[vt[n.first].first]--;
          cnt[vt[n.second].first]--;
          pq.push({cnt[vt[n.first].first], vt[n.first].first});
          pq.push({cnt[vt[n.second].first], vt[n.second].first});
          if (prv[n.first] == -1) {
            if (nxt[n.second] == (int)vt.size()) {
              continue;
            } else {
              prv[nxt[n.second]] = -1;
            }
          } else {
            if (nxt[n.second] == (int)vt.size()) {
              nxt[prv[n.first]] = (int)vt.size();
            } else {
              prv[nxt[n.second]] = prv[n.first];
              nxt[prv[n.first]] = nxt[n.second];
              int i1 = prv[n.first], i2 = nxt[n.second];
              prv[i2] = i1;
              nxt[i1] = i2;
              if (vt[i1].first != vt[i2].first) {
                gp1[vt[i1].first].push_back({i1, i2});
                gp1[vt[i2].first].push_back({i1, i2});
              }
            }
          }
          tf = true;
          break;
        }
      }
      if (tf) continue;
      int prv = -1;
      for (int i = 0; i < vt.size(); i++) {
        if (chk[i] == false) {
          ans.push_back({prv, i});
          prv = i;
        }
      }
      ans.push_back({prv, vt.size()});
      tf2 = true;
      break;
    }
    if (!tf2) {
      ans.push_back({-1, vt.size()});
    }
    for (int i = 1; i <= N; i++) {
      tree[i] = 0;
    }
    for (int i = 1; i <= N; i++) {
      Add(i, 1);
    }
    printf("%d\n", (int)ans.size());
    for (int i = 0; i < ans.size(); i++) {
      int l, r;
      if (ans[i].first == -1) {
        l = 1;
      } else {
        l = vt[ans[i].first].second + 2;
      }
      if (ans[i].second == vt.size()) {
        r = N;
      } else {
        r = vt[ans[i].second].second + 1;
      }
      int cl = Sum(l), cr = Sum(r);
      printf("%d %d\n", cl, cr);
      Add(r, cl - cr - 1);
    }
  }
  return 0;
}