Sereja and Algorithm

Sereja loves all sorts of algorithms. He has recently come up with a new algorithm, which receives a string as an input. Let’s represent the input string of the algorithm as q = q 1 q 2… q k. The algorithm consists of two steps:

  1. Find any continuous subsequence (substring) of three characters of string q, which doesn’t equal to either string “zyx”, “xzy”, “yxz”. If q doesn’t contain any such subsequence, terminate the algorithm, otherwise go to step 2.
  2. Rearrange the letters of the found subsequence randomly and go to step 1.

Sereja thinks that the algorithm works correctly on string q if there is a non-zero probability that the algorithm will be terminated. But if the algorithm anyway will work for infinitely long on a string, then we consider the algorithm to work incorrectly on this string.

Sereja wants to test his algorithm. For that, he has string s = s 1 s 2… s n, consisting of n characters. The boy conducts a series of m tests. As the i-th test, he sends substring s l i s l i + 1… s r i (1 ≤ l i ≤ r i ≤ n) to the algorithm input. Unfortunately, the implementation of his algorithm works too long, so Sereja asked you to help. For each test (l i, r i) determine if the algorithm works correctly on this test or not.

Input

The first line contains non-empty string s, its length ( n) doesn’t exceed 105. It is guaranteed that string s only contains characters: ‘x’, ‘y’, ‘z’.

The second line contains integer m (1 ≤ m ≤ 105) — the number of tests. Next m lines contain the tests. The i-th line contains a pair of integers l ir i (1 ≤ l i ≤ r i ≤ n).

Output

For each test, print “YES” (without the quotes) if the algorithm works correctly on the corresponding test and “NO” (without the quotes) otherwise.

Examples

input

zyxxxxxxyyz
5
5 5
1 3
1 11
1 4
3 6

output

YES
YES
NO
YES
NO

Note

In the first example, in test one and two the algorithm will always be terminated in one step. In the fourth test you can get string “xzyx” on which the algorithm will terminate. In all other tests the algorithm doesn’t work correctly.

Solution:

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

const int N = 2000010;

char s[N];
int x[N], y[N], z[N];

int main() {
scanf("%s", s);
int n = strlen(s);
x[0] = y[0] = z[0] = 0;
for (int i = 0; i < n; i++) {
    x[i + 1] = x[i] + (s[i] == 'x');
    y[i + 1] = y[i] + (s[i] == 'y');
    z[i + 1] = z[i] + (s[i] == 'z');
  }
  int tt;
  scanf("%d", &tt);
  while (tt--) {
    int a, b;
    scanf("%d %d", &a, &b);
    int nx = x[b] - x[a - 1];
    int ny = y[b] - y[a - 1];
    int nz = z[b] - z[a - 1];
    bool ok = true;
    if (nx - ny > 1 || nx - nz > 1 || ny - nz > 1) ok = false;
if (ny - nx > 1 || nz - nx > 1 || nz - ny > 1) ok = false;
if (nx + ny + nz <= 2) ok = true;
    puts(ok ? "YES" : "NO");
  }
  return 0;
}