#include <bits/stdc++.h>
using namespace std;
vector<int> seg;
int S;
void build(int n) {
  S = (1 << (int)(ceil(log2(n))));
  seg = vector<int>(S * 2, 0);
}
void update(int a, int b, int v, int j = 1, int l = 0, int r = S - 1) {
  if (r < a || b < l) return;
  if (a <= l && r <= b) {
    seg[j] += v;
  } else {
    update(a, b, v, j * 2, l, (l + r) / 2);
    update(a, b, v, j * 2 + 1, (l + r) / 2 + 1, r);
  }
}
int query(int a, int j = 1, int l = 0, int r = S - 1) {
  if (a == l && a == r) return seg[j];
  int mid = (l + r) / 2;
  if (a <= mid)
    return seg[j] + query(a, j * 2, l, mid);
  else
    return seg[j] + query(a, j * 2 + 1, mid + 1, r);
}
set<pair<int, int>> B;
vector<int> s;
map<char, set<pair<int, int>>> isect[26];
void _Erase(set<pair<int, int>>::iterator x, set<pair<int, int>>::iterator y) {
  int ch = s[x->first];
  int dh = s[y->first];
  isect[ch][dh].erase({x->second, y->first});
  if (isect[ch][dh].empty()) isect[ch].erase(dh);
  if (ch == dh) return;
  swap(ch, dh);
  isect[ch][dh].erase({x->second, y->first});
  if (isect[ch][dh].empty()) isect[ch].erase(dh);
}
void _Add(set<pair<int, int>>::iterator x, set<pair<int, int>>::iterator y) {
  isect[s[x->first]][s[y->first]].insert({x->second, y->first});
  isect[s[y->first]][s[x->first]].insert({x->second, y->first});
}
void Erase(set<pair<int, int>>::iterator x) {
  if (x != B.begin()) {
    _Erase(prev(x), x);
  }
  if (next(x) != B.end()) {
    _Erase(x, next(x));
  }
  if (x != B.begin() && next(x) != B.end()) {
    _Add(prev(x), next(x));
  }
}
void Add(set<pair<int, int>>::iterator x) {
  if (x != B.begin() && next(x) != B.end()) {
    _Erase(prev(x), next(x));
  }
  if (x != B.begin()) {
    _Add(prev(x), x);
  }
  if (next(x) != B.end()) {
    _Add(x, next(x));
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    int n;
    string ss;
    vector<pair<int, int>> ans;
    vector<int> cnt(26, 0);
    cin >> ss;
    n = ((int)(ss).size());
    for (int i = 0; i < n; i++) s.push_back(ss[i] - 'a');
    build(n);
    for (int i = 1; i < n; i++) {
      if (s[i] == s[i - 1]) cnt[s[i]]++;
    }
    vector<int> CC(n, 1);
    for (int i = n - 2; i >= 0; i--) {
      if (s[i] == s[i + 1]) CC[i] = CC[i + 1] + 1;
    }
    for (int i = 0; i < n; i += CC[i]) {
      if (CC[i] != 1) {
        Add(B.insert({i, i + CC[i] - 1}).first);
      }
    }
    auto choose = [&]() {
      return max_element((cnt).begin(), (cnt).end()) - cnt.begin();
    };
    int ch = 0, SZ = n;
    while (cnt[(ch = choose())]) {
      int a, b;
      if (((int)(isect[ch]).size()) == 0) {
        a = B.begin()->first;
        b = B.begin()->second;
        a = a + query(a);
        b = b + query(b);
        for (int i = 0; i < b - a; i++) {
          int aa = b - i;
          int bb = SZ - 1;
          ans.push_back({aa, bb});
          SZ -= (bb - aa + 1);
        }
        break;
      } else if (((int)(isect[ch]).size()) == 1 && isect[ch].count(ch)) {
        a = isect[ch][ch].rbegin()->first;
        b = isect[ch][ch].rbegin()->second;
      } else {
        int dh = isect[ch].begin()->first;
        if (dh == ch) dh = (++isect[ch].begin())->first;
        a = isect[ch][dh].rbegin()->first;
        b = isect[ch][dh].rbegin()->second;
      }
      auto X = --B.upper_bound({a, 1e9});
      auto Y = --B.upper_bound({b, 1e9});
      int a1 = X->first, a2 = X->second;
      int b1 = Y->first, b2 = Y->second;
      int aa = a2 + query(a2);
      int bb = b1 + query(b1);
      ans.push_back({aa, bb});
      update(a2, S - 1, -(bb - aa + 1));
      SZ -= (bb - aa + 1);
      cnt[s[a2]]--;
      cnt[s[b1]]--;
      a2--;
      b1++;
      Erase(X);
      B.erase(X);
      Erase(Y);
      B.erase(Y);
      if (s[a2] == s[b1]) {
        cnt[s[a2]]++;
        if (a1 != b2) Add(B.insert({a1, b2}).first);
      } else {
        if (a1 != a2) {
          Add(B.insert({a1, a2}).first);
        }
        if (b1 != b2) {
          Add(B.insert({b1, b2}).first);
        }
      }
    }
    ans.push_back({0, SZ - 1});
    cout << ((int)(ans).size()) << "\n";
    for (auto p : ans) cout << p.first + 1 << " " << p.second + 1 << "\n";
    B.clear();
    s.clear();
    for (int i = 0; i < 26; i++) isect[i].clear();
  }
}

### Prompt

Please provide a CPP coded solution to the problem described below:

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> seg;
int S;
void build(int n) {
  S = (1 << (int)(ceil(log2(n))));
  seg = vector<int>(S * 2, 0);
}
void update(int a, int b, int v, int j = 1, int l = 0, int r = S - 1) {
  if (r < a || b < l) return;
  if (a <= l && r <= b) {
    seg[j] += v;
  } else {
    update(a, b, v, j * 2, l, (l + r) / 2);
    update(a, b, v, j * 2 + 1, (l + r) / 2 + 1, r);
  }
}
int query(int a, int j = 1, int l = 0, int r = S - 1) {
  if (a == l && a == r) return seg[j];
  int mid = (l + r) / 2;
  if (a <= mid)
    return seg[j] + query(a, j * 2, l, mid);
  else
    return seg[j] + query(a, j * 2 + 1, mid + 1, r);
}
set<pair<int, int>> B;
vector<int> s;
map<char, set<pair<int, int>>> isect[26];
void _Erase(set<pair<int, int>>::iterator x, set<pair<int, int>>::iterator y) {
  int ch = s[x->first];
  int dh = s[y->first];
  isect[ch][dh].erase({x->second, y->first});
  if (isect[ch][dh].empty()) isect[ch].erase(dh);
  if (ch == dh) return;
  swap(ch, dh);
  isect[ch][dh].erase({x->second, y->first});
  if (isect[ch][dh].empty()) isect[ch].erase(dh);
}
void _Add(set<pair<int, int>>::iterator x, set<pair<int, int>>::iterator y) {
  isect[s[x->first]][s[y->first]].insert({x->second, y->first});
  isect[s[y->first]][s[x->first]].insert({x->second, y->first});
}
void Erase(set<pair<int, int>>::iterator x) {
  if (x != B.begin()) {
    _Erase(prev(x), x);
  }
  if (next(x) != B.end()) {
    _Erase(x, next(x));
  }
  if (x != B.begin() && next(x) != B.end()) {
    _Add(prev(x), next(x));
  }
}
void Add(set<pair<int, int>>::iterator x) {
  if (x != B.begin() && next(x) != B.end()) {
    _Erase(prev(x), next(x));
  }
  if (x != B.begin()) {
    _Add(prev(x), x);
  }
  if (next(x) != B.end()) {
    _Add(x, next(x));
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    int n;
    string ss;
    vector<pair<int, int>> ans;
    vector<int> cnt(26, 0);
    cin >> ss;
    n = ((int)(ss).size());
    for (int i = 0; i < n; i++) s.push_back(ss[i] - 'a');
    build(n);
    for (int i = 1; i < n; i++) {
      if (s[i] == s[i - 1]) cnt[s[i]]++;
    }
    vector<int> CC(n, 1);
    for (int i = n - 2; i >= 0; i--) {
      if (s[i] == s[i + 1]) CC[i] = CC[i + 1] + 1;
    }
    for (int i = 0; i < n; i += CC[i]) {
      if (CC[i] != 1) {
        Add(B.insert({i, i + CC[i] - 1}).first);
      }
    }
    auto choose = [&]() {
      return max_element((cnt).begin(), (cnt).end()) - cnt.begin();
    };
    int ch = 0, SZ = n;
    while (cnt[(ch = choose())]) {
      int a, b;
      if (((int)(isect[ch]).size()) == 0) {
        a = B.begin()->first;
        b = B.begin()->second;
        a = a + query(a);
        b = b + query(b);
        for (int i = 0; i < b - a; i++) {
          int aa = b - i;
          int bb = SZ - 1;
          ans.push_back({aa, bb});
          SZ -= (bb - aa + 1);
        }
        break;
      } else if (((int)(isect[ch]).size()) == 1 && isect[ch].count(ch)) {
        a = isect[ch][ch].rbegin()->first;
        b = isect[ch][ch].rbegin()->second;
      } else {
        int dh = isect[ch].begin()->first;
        if (dh == ch) dh = (++isect[ch].begin())->first;
        a = isect[ch][dh].rbegin()->first;
        b = isect[ch][dh].rbegin()->second;
      }
      auto X = --B.upper_bound({a, 1e9});
      auto Y = --B.upper_bound({b, 1e9});
      int a1 = X->first, a2 = X->second;
      int b1 = Y->first, b2 = Y->second;
      int aa = a2 + query(a2);
      int bb = b1 + query(b1);
      ans.push_back({aa, bb});
      update(a2, S - 1, -(bb - aa + 1));
      SZ -= (bb - aa + 1);
      cnt[s[a2]]--;
      cnt[s[b1]]--;
      a2--;
      b1++;
      Erase(X);
      B.erase(X);
      Erase(Y);
      B.erase(Y);
      if (s[a2] == s[b1]) {
        cnt[s[a2]]++;
        if (a1 != b2) Add(B.insert({a1, b2}).first);
      } else {
        if (a1 != a2) {
          Add(B.insert({a1, a2}).first);
        }
        if (b1 != b2) {
          Add(B.insert({b1, b2}).first);
        }
      }
    }
    ans.push_back({0, SZ - 1});
    cout << ((int)(ans).size()) << "\n";
    for (auto p : ans) cout << p.first + 1 << " " << p.second + 1 << "\n";
    B.clear();
    s.clear();
    for (int i = 0; i < 26; i++) isect[i].clear();
  }
}

```