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 TH>
void _dbg(const char* sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t) {
  while (*sdbg != ',') {
    cerr << *sdbg++;
  }
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, t...);
}
template <class C>
void mini(C& a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C& a4, C b4) {
  a4 = max(a4, b4);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> pair) {
  return out << "(" << pair.first << ", " << pair.second << ")";
}
template <class A, class B, class C>
struct Triple {
  A first;
  B second;
  C third;
  bool operator<(const Triple& t) const {
    if (first != t.first) return first < t.first;
    if (second != t.second) return second < t.second;
    return third < t.third;
  }
};
template <class T>
void ResizeVec(T&, vector<long long>) {}
template <class T>
void ResizeVec(vector<T>& vec, vector<long long> sz) {
  vec.resize(sz[0]);
  sz.erase(sz.begin());
  if (sz.empty()) {
    return;
  }
  for (T& v : vec) {
    ResizeVec(v, sz);
  }
}
template <class A, class B, class C>
ostream& operator<<(ostream& out, Triple<A, B, C> t) {
  return out << "(" << t.first << ", " << t.second << ", " << t.third << ")";
}
template <class T>
ostream& operator<<(ostream& out, vector<T> vec) {
  out << "(";
  for (auto& v : vec) out << v << ", ";
  return out << ")";
}
template <class T>
ostream& operator<<(ostream& out, set<T> vec) {
  out << "(";
  for (auto& v : vec) out << v << ", ";
  return out << ")";
}
template <class L, class R>
ostream& operator<<(ostream& out, map<L, R> vec) {
  out << "(";
  for (auto& v : vec) out << v << ", ";
  return out << ")";
}
vector<pair<long long, long long>> que[256][256];
vector<long long> que1[256];
struct Dwu {
  Dwu(long long n) {
    l.resize(n + 2);
    r.resize(n + 2);
    alive.resize(n + 2);
    for (long long i = (1); i <= (n + 1); ++i) {
      l[i] = i - 1;
    }
    for (long long i = 0; i < (n + 1); ++i) {
      r[i] = i + 1;
    }
    for (long long i = (1); i <= (n); ++i) {
      alive[i] = 1;
    }
  }
  vector<long long> l, r, alive;
  long long Rem(long long a) {
    assert(alive[a]);
    long long R = r[a];
    long long L = l[a];
    r[L] = R;
    l[R] = L;
    alive[a] = 0;
    return R;
  }
};
long long Magic(long long n) { return n - (n & (n - 1)); }
struct Sol {
  void Test() {
    for (long long i = ('a'); i <= ('z'); ++i) {
      que1[i].clear();
      for (long long j = ('a'); j <= ('z'); ++j) {
        que[i][j].clear();
      }
    }
    string s;
    cin >> s;
    long long n = ((long long)(s).size());
    vector<long long> fenw(n + 2);
    auto Up = [&](long long x) {
      while (x < n + 2) {
        fenw[x]++;
        x += Magic(x);
      }
    };
    auto Left = [&](long long x) {
      long long sum = 0;
      while (x) {
        sum += fenw[x];
        x -= Magic(x);
      }
      return sum;
    };
    Dwu all(n + 1);
    vector<pair<char, long long>> eqs;
    for (long long i = 0; i < (n - 1); ++i) {
      if (s[i] == s[i + 1]) {
        eqs.push_back({s[i], i + 1});
      }
    }
    Dwu cons(((long long)(eqs).size()) + 2);
    vector<long long> cnt('z' + 2);
    for (auto eq : eqs) {
      cnt[eq.first]++;
    }
    eqs.insert(eqs.begin(), pair<char, long long>('$', -1));
    auto Put = [&](long long a, long long b) {
      assert(a < b);
      long long la = eqs[a].first;
      long long lb = eqs[b].first;
      que[la][lb].push_back({a, b});
      que[lb][la].push_back({a, b});
      assert(cons.alive[a]);
      assert(cons.alive[b]);
      assert(cons.r[a] == b);
    };
    for (long long i = (1); i <= (((long long)(eqs).size()) - 2); ++i) {
      Put(i, i + 1);
    }
    vector<pair<long long, long long>> ans;
    while (1) {
      long long ma = 0;
      long long wh_ma = 0;
      for (long long i = ('a'); i <= ('z'); ++i) {
        if (cnt[i]) {
          ((char)i, cnt[i]);
        }
        if (cnt[i] > ma) {
          wh_ma = i;
          ma = cnt[i];
        }
      }
      if (ma == 0) {
        break;
      }
      ((char)wh_ma, ma);
      long long any = 0;
      for (long long oth = ('a'); oth <= ('z'); ++oth) {
        if (oth == wh_ma) {
          continue;
        }
        while (!que[wh_ma][oth].empty()) {
          auto p = que[wh_ma][oth].back();
          if (cons.alive[p.first] && cons.alive[p.second]) {
            (p.first, p.second);
            any = 1;
            long long l = eqs[min(p.first, p.second)].second + 1;
            long long r = eqs[max(p.first, p.second)].second;
            ans.push_back({l - Left(l), r - Left(r)});
            long long cur = l;
            while (cur <= r) {
              Up(cur);
              cur = all.Rem(cur);
            }
            cnt[wh_ma]--;
            cnt[oth]--;
            cons.Rem(p.first);
            long long R = cons.Rem(p.second);
            long long L = cons.l[R];
            (L, R);
            if (L >= 1 && R <= ((long long)(eqs).size()) - 1) {
              Put(L, R);
            }
            goto End;
          } else {
            que[wh_ma][oth].pop_back();
          }
        }
      }
    End:;
      if (any) {
        continue;
      }
      for (long long i = (1); i <= (((long long)(eqs).size()) - 1); ++i) {
        if (cons.alive[i]) {
          long long l = eqs[i].second + 1;
          ans.push_back({l - Left(l), l - Left(l)});
          cons.Rem(i);
          Up(l);
        }
      }
      break;
    }
    ans.push_back({1, n - Left(n)});
    cout << ((long long)(ans).size()) << "\n";
    for (auto x : ans) {
      cout << x.first << " " << x.second << "\n";
    }
  }
};
int32_t main() {
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  if (0) cout << fixed << setprecision(10);
  cin.tie(0);
  long long t;
  cin >> t;
  for (long long i = (1); i <= (t); ++i) {
    Sol sol;
    sol.Test();
  }
  return 0;
}