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;
int t, n, sum[1000005], lazy[1000005], tans[200005][2], tt;
int c[200005], ct;
char s[200005];
set<int> st, f[26], g[26];
void pushup(int x) { sum[x] = sum[x * 2] + sum[x * 2 + 1]; }
void col(int x) {
  lazy[x] = 1;
  sum[x] = 0;
}
void pushdown(int x) {
  if (lazy[x]) {
    col(x * 2);
    col(x * 2 + 1);
    lazy[x] = 0;
  }
}
void modify(int x, int l, int r, int ql, int qr) {
  if (l > qr || r < ql) return;
  if (ql <= l && r <= qr) {
    col(x);
    return;
  }
  int mid = (l + r) / 2;
  modify(x * 2, l, mid, ql, qr);
  modify(x * 2 + 1, mid + 1, r, ql, qr);
  pushup(x);
}
int query(int x, int l, int r, int ql, int qr) {
  if (l > qr || r < ql) return 0;
  if (ql <= l && r <= qr) return sum[x];
  int mid = (l + r) / 2, q1, q2;
  q1 = query(x * 2, l, mid, ql, qr);
  q2 = query(x * 2 + 1, mid + 1, r, ql, qr);
  return q1 + q2;
}
void print(int l, int r) {
  int tl = query(1, 1, n, 1, l - 1) + 1, tr = query(1, 1, n, 1, r);
  modify(1, 1, n, l, r);
  tans[++tt][0] = tl;
  tans[tt][1] = tr;
}
void del(int x) {
  st.erase(x);
  f[s[x] - 'a'].erase(x);
  g[s[x] - 'a'].erase(x);
}
void upd(int x) {
  set<int>::iterator nw = st.find(x);
  int val = s[x] - 'a';
  g[val].erase(x);
  if (nw != st.begin()) {
    nw--;
    if (s[*nw] != s[x]) g[val].insert(x);
    nw++;
  }
  if (nw != st.end()) {
    nw++;
    if (nw != st.end() && s[*nw] != s[x]) g[val].insert(x);
  }
}
void build(int x, int l, int r) {
  lazy[x] = 0;
  if (l == r) {
    sum[x] = 1;
    return;
  }
  int mid = (l + r) / 2;
  build(x * 2, l, mid);
  build(x * 2 + 1, mid + 1, r);
  pushup(x);
}
int main() {
  scanf("%d", &t);
  while (t--) {
    tt = 0;
    st.clear();
    scanf("%s", s + 1);
    n = strlen(s + 1);
    build(1, 1, n);
    for (int i = 0; i < 26; i++) g[i].clear(), f[i].clear();
    ct = 0;
    for (int i = 1; i < n; i++)
      if (s[i] == s[i + 1]) {
        st.insert(i);
        f[s[i] - 'a'].insert(i);
        c[++ct] = i;
        if (ct > 1 && s[c[ct]] != s[c[ct - 1]]) {
          g[s[i] - 'a'].insert(i);
          g[s[c[ct - 1]] - 'a'].insert(c[ct - 1]);
        }
      }
    while (1) {
      int mx = 0, id = 0;
      for (int i = 0; i < 26; i++)
        if ((int)f[i].size() > mx) {
          mx = f[i].size();
          id = i;
        }
      if (!mx) break;
      if (g[id].empty()) {
        int las = 1;
        for (set<int>::iterator i = st.begin(); i != st.end(); i++)
          print(las, *i), las = *i + 1;
        break;
      }
      int u = *g[id].begin(), v;
      set<int>::iterator nw = st.lower_bound(u);
      if (nw != st.begin()) {
        nw--;
        if (s[*nw] != s[u])
          v = *nw;
        else
          v = u, u = *++(++nw);
      } else
        v = u, u = *++nw;
      print(v + 1, u);
      del(u), del(v);
      nw = st.upper_bound(u);
      if (nw != st.end()) upd(*nw);
      if (nw != st.begin()) upd(*--nw);
    }
    print(1, n);
    printf("%d\n", tt);
    for (int i = 1; i <= tt; i++) printf("%d %d\n", tans[i][0], tans[i][1]);
  }
  return 0;
}