A Game on Strings

Alice and Bob are playing a game on strings.

Initially, they have some string $t$. In one move the first player selects the character $c$ present in $t$ and erases all it’s occurrences in $t$, thus splitting $t$ into many smaller strings. The game then goes independently with each of the strings — to make the move player selects one of the strings and one of the characters there, deletes all occurrences and adds the remaining string back to the game.

Alice always starts the game, and then Alice and Bob take turns making moves. The player who is unable to make a move (because there is no string left) loses.

Alice and Bob used to always start with a string $s$, but recently they found out that this became too boring. Now before each game they choose two integers $l$ and $r$ such that $1 \le l \le r \le |s|$ and play the game with the string $s_{l} s_{l+1} s_{l+2} \ldots s_{r}$ instead.

Given the string $s$ and integers $l$, $r$ for each game. Find who is going to win each game assuming they are smart and are playing optimally.

Input

The first line contains the string $s$ ($1 \le |s| \le 10^5$) consisting of lowercase English letters. This is the string Alice and Bob used to start with.

The second line contains a single integer $m$ ($1 \le m \le 10^5$) — the number of games to analyze.

Each of the next $m$ lines contains two integers $l$ and $r$ ($1 \le l \le r \le |s|$) — the bounds of the starting substring in the string $s$.

Output

For each game output a single line containing the name of the winner — “Alice” or “Bob” respectively.

Examples

input

aaab
2
1 2
1 4

output

Alice
Bob

input

aaccbdb
2
5 7
1 7

output

Alice
Alice

Note

In the first example,

  1. In the first game the string “aa” is selected. Alice deletes character ‘a’ and Bob is unable to move.
  2. In the second game the string “aaab” is selected. No matter what character Alice will delete, Bob deletes the other one and Alice is unable to move.

In the second example Alice wins both game “bdb” and “aaccbdb”.

To win game “bdb” Alice can erase symbol ‘d’, the game then goes independently on strings “b” and “b”. Bob deletes one of this strings and the Alice deletes the other one and Bob is unable to move.

To win game “aaccbdb” Alice can erase symbol ‘d’, the game then goes independently on strings “aaccb” and “b”. It is possible to show, that no matter what are the moves, the remaining game can only finish in exactly $4$ moves, so the Bob will be unable to move after that.

Solution:

#include <bits/stdc++.h>

using namespace std;

const int ALPHA = 26;
const int MAX_G = 32;

int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string foo;
cin >> foo;
int n = (int) foo.size();
vector<int> s(n);
for (int i = 0; i < n; i++) {
    s[i] = (int) (foo[i] - 'a');
  }
  vector<vector<int>> nxt(n + 1, vector<int>(ALPHA));
for (int c = 0; c < ALPHA; c++) {
    nxt[n] = n;
  }
  for (int i = n - 1; i >= 0; i--) {
for (int c = 0; c < ALPHA; c++) {
      nxt[i] = nxt[i + 1];
    }
    nxt[i][s[i]] = i;
  }
  vector<vector<int>> prv(n + 1, vector<int>(ALPHA));
for (int c = 0; c < ALPHA; c++) {
    prv[0] = -1;
  }
  for (int i = 0; i < n; i++) {
    for (int c = 0; c < ALPHA; c++) {
      prv[i + 1] = prv[i];
    }
    prv[i + 1][s[i]] = i;
  }
  int m;
  cin >> m;
vector<int> from(m), to(m);
for (int i = 0; i < m; i++) {
    cin >> from[i] >> to[i];
from[i]--; to[i]--;
}
vector<vector<int>> add(n);
for (int i = 0; i < m; i++) {
    add[from[i]].push_back(to[i]);
    for (int c = 0; c < ALPHA; c++) {
      int j = prv[to[i] + 1];
      if (j < to[i] && j >= from[i]) {
add[j + 1].push_back(to[i]);
}
}
}
vector<vector<int>> rs(n);
vector<vector<int>> dp(n);
auto get_dp = [&](int i, int j) {
if (i > j) {
return 0;
}
auto it = lower_bound(rs[i].begin(), rs[i].end(), j);
assert(!(it == rs[i].end() || *it != j));
int pos = (int) (it - rs[i].begin());
return dp[i][pos];
};
vector<vector<int>> get_dp_to(n + 1, vector<int>(ALPHA));
vector<vector<int>> get_dp_from(n + 1, vector<int>(ALPHA));
vector<int> xorval(n + 1, 0);
vector<int> touched(MAX_G, 0);
int iter = 0;
for (int i = n - 1; i >= 0; i--) {
if (i < n - 1) {
      int j = nxt[i + 1][s[i]];
      xorval[i] = xorval[j] ^ get_dp(i + 1, j - 1);
    }
    for (int c = 0; c < ALPHA; c++) {
      if (nxt[i] != n && nxt[i] != i) {
        rs[i].push_back(nxt[i] - 1);
      }
    }
    rs[i].push_back(n - 1);
    for (int j : add[i]) {
      rs[i].push_back(j);
    }
    sort(rs[i].begin(), rs[i].end());
    rs[i].resize(unique(rs[i].begin(), rs[i].end()) - rs[i].begin());
    dp[i].resize(rs[i].size());
    for (int jt = 0; jt < (int) rs[i].size(); jt++) {
      int j = rs[i][jt];
      iter++;
      for (int c = 0; c < ALPHA; c++) {
        if (nxt[i] > j) {
continue;
}
int A = nxt[i];
int B = prv[j + 1];
int cur = 0;
if (A > i) {
cur ^= get_dp_to[i];
}
if (B < j) {
          cur ^= get_dp_from[j];
        }
        cur ^= xorval[A] ^ xorval[B];
        touched[cur] = iter;
      }
      int &res = dp[i][jt];
      res = 0;
      while (touched[res] == iter) {
        res++;
      }
      if (j < n - 1) {
        if (nxt[i][s[j + 1]] == j + 1) {
          get_dp_to[i][s[j + 1]] = res;
        }
      }
      if (i > 0) {
if (prv[j + 1][s[i - 1]] == i - 1) {
get_dp_from[j][s[i - 1]] = res;
}
}
}
}
for (int i = 0; i < m; i++) {
    int x = get_dp(from[i], to[i]);
    cout << (x > 0 ? "Alice" : "Bob") << '\n';
  }
  return 0;
}