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 + 10, A = 26;
int tree[4 * N];
set<pair<int, int> > where[A][A];
void del(int p, int len, int& cur_len, int n, vector<pair<int, int> >& ans);
void update(int i, int l, int r, int p, int x);
int query(int i, int l, int r, int ql, int qr);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    for (auto& c : s) {
      c -= 'a';
    }
    int n = s.length();
    s = 'a' + s;
    memset(tree, 0, sizeof(tree[0]) * 4 * (n + 1));
    for (int x = 0; x < A; ++x) {
      for (int y = 0; y < A; ++y) {
        where[x][y].clear();
      }
    }
    set<pair<int, int> > pairs;
    vector<int> cnt(A, 0), lpartner(n + 1, 0), rpartner(n + 1, 0);
    for (int i = 1; i < n; ++i) {
      if (s[i] == s[i + 1]) {
        pairs.insert({i, i + 1});
        rpartner[i] = i + 1;
        lpartner[i + 1] = i;
        ++cnt[s[i]];
      }
    }
    if (pairs.size() >= 2) {
      auto prv = pairs.begin();
      auto it = next(prv);
      while (it != pairs.end()) {
        int c1 = s[prv->first], c2 = s[it->first];
        where[c1][c2].insert({prv->second, it->first});
        where[c2][c1].insert({prv->second, it->first});
        ++prv;
        ++it;
      }
    }
    vector<pair<int, int> > ans;
    int cur_len = n;
    while (cur_len) {
      if (pairs.empty()) {
        ans.push_back({1, cur_len});
        break;
      } else if (pairs.size() == 1) {
        int p = (pairs.begin())->first;
        del(1, p, cur_len, n, ans);
        pairs.clear();
      } else {
        int maj = 0;
        for (int i = 0; i < A; ++i) {
          if (cnt[i] > cnt[maj]) {
            maj = i;
          }
        }
        int type = (cnt[maj] == pairs.size()) ? 1 : 2;
        for (int j = 0; j < A; ++j) {
          if (type == 2 and j == maj) {
            continue;
          } else if (!where[j][maj].empty()) {
            auto cur = *where[j][maj].begin();
            where[j][maj].erase(where[j][maj].begin());
            where[maj][j].erase(cur);
            int q1 = cur.first, p2 = cur.second;
            int p1 = lpartner[q1], q2 = rpartner[p2];
            pairs.erase({p1, q1});
            pairs.erase({p2, q2});
            del(q1, p2, cur_len, n, ans);
            --cnt[j];
            --cnt[maj];
            if (j == maj) {
              ++cnt[j];
              pairs.insert({p1, q2});
              rpartner[p1] = q2;
              lpartner[q2] = p1;
            } else {
              auto it = pairs.lower_bound({q2, 0});
              int x = -1, y = -1;
              if (it != pairs.end()) {
                int c = s[it->first];
                where[s[q2]][c].erase({q2, it->first});
                where[c][s[q2]].erase({q2, it->first});
                y = it->first;
              }
              if (it != pairs.begin()) {
                it = prev(it);
                int c = s[it->second];
                where[s[p1]][c].erase({it->second, p1});
                where[c][s[p1]].erase({it->second, p1});
                x = it->second;
              }
              if (x != -1 and y != -1) {
                where[s[x]][s[y]].insert({x, y});
                where[s[y]][s[x]].insert({x, y});
              }
            }
            break;
          }
        }
      }
    }
    cout << ans.size() << '\n';
    for (auto& p : ans) {
      cout << p.first << ' ' << p.second << '\n';
    }
  }
}
void del(int p, int q, int& cur_len, int n, vector<pair<int, int> >& ans) {
  int l = p - query(1, 1, n, 1, p);
  int r = q - query(1, 1, n, 1, q);
  int len = r - l + 1;
  ans.push_back({l, r});
  update(1, 1, n, p, len);
  cur_len -= len;
}
void update(int i, int l, int r, int p, int x) {
  if (p < l or p > r) {
    return;
  } else if (l == r) {
    tree[i] += x;
  } else {
    int mid = (l + r) / 2, lc = 2 * i, rc = lc + 1;
    update(lc, l, mid, p, x);
    update(rc, mid + 1, r, p, x);
    tree[i] = tree[lc] + tree[rc];
  }
}
int query(int i, int l, int r, int ql, int qr) {
  if (l > qr or ql > r) {
    return 0;
  } else if (ql <= l and r <= qr) {
    return tree[i];
  } else {
    int mid = (l + r) / 2, lc = 2 * i, rc = lc + 1;
    return query(lc, l, mid, ql, qr) + query(rc, mid + 1, r, ql, qr);
  }
}