Problem: Professor Bajtocy is conducting experiments on alien DNA. He has discovered that it is subject to repetitive mutations — each mutation happens in the same way: some continuous subsequence of the alien DNA becomes active, copies itself, the copy gets mangled and inserts itself right after the original subsequence. The mangled copy of the activated continuous subsequence is formed by first joining all the elements at the even positions in that subsequence, and then joining all the elements at the odd ones at the end. That is, if the activated subsequence consists of 11 elements and represented as s1s2... s11, its mangled copy is s2s4s6s8s10s1s3s5s7s9s11.

For example, if the original sequence was "ACTGG" and the mutation happened on the segment [2, 4] (that is the activated subsequence is "CTG"), the mutated DNA is: "ACTGTCGG". The mangled copy of the activated subsequence is marked with bold font.

Professor Bajtocy has written down the original DNA sequence and the mutations that sequentially happened to it, and he now asks you to recover the first k elements of the DNA sequence after all the mutations.

Input

The first line of input contains the original DNA sequence, consisting only of letters "A", "C", "T" and "G" and not exceeding 3·106 in length. 

The second line contains a single integer k (1 ≤ k ≤ 3·106).

The third line contains a single integer n (0 ≤ n ≤ 5000) — the number of mutations. The next n lines describe the mutations in chronological order — each mutation is described by two numbers li and ri (1 ≤ li ≤ ri ≤ 109), meaning that the continuous subsequence [li, ri] has become active and cloned itself, joining itself with the mangled copy. 

It is guaranteed that the input data is correct, that is, no mutation acts on non-existing elements of the DNA sequence, and the resulting DNA sequence has at least k elements.

Assume that the DNA elements are indexed starting from 1 and that the notation [l, r] meaning the continuous subsequence of DNA sequence that consists of r - l + 1 elements starting at the l-th DNA sequence element and ending at the r-th DNA sequence element.

Output

Output a single line, containing the first k letters of the mutated DNA sequence.

Examples

Input

GAGA
4
0


Output

GAGA


Input

ACGTACGT
16
2
1 2
2 8


Output

ACCAGTACCGACATCG

Note

In the second example, after the first mutation the sequence is "ACCAGTACGT". After the second mutation it's "ACCAGTACCGACATCGT".

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const long long int INFLL = 0x3f3f3f3f3f3f3f3fll;
long long int getint() {
  long long int ret = 0;
  bool f = 0;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') f ^= 1;
  while (c >= '0' && c <= '9') {
    ret = ret * 10 + c - '0';
    c = getchar();
  }
  return f ? -ret : ret;
}
using namespace std;
const int MAXK = 3000000;
const int MAXN = 5000;
int ch[2][MAXK + 10], sz[MAXK + 10], fa[MAXK + 10], *lc = ch[0], *rc = ch[1],
                                                    rt;
int cnt = 0;
void update(int u) { sz[u] = sz[lc[u]] + sz[rc[u]] + 1; }
void rotate(int x) {
  int y = fa[x], z = fa[y];
  bool f = rc[y] == x;
  fa[fa[fa[ch[f][y] = ch[!f][x]] = y] = x] = z;
  ch[!f][x] = y;
  if (z) ch[rc[z] == y][z] = x;
  update(y);
}
void splay(int x, int f = 0) {
  for (int y = fa[x]; y != f; rotate(x), y = fa[x]) {
    int z = fa[y];
    if (z != f) {
      if ((lc[z] == y) == (lc[y] == x))
        rotate(y);
      else
        rotate(x);
    }
  }
  update(x);
  if (!f) rt = x;
}
int build(int l, int r, int f) {
  if (l > r) return 0;
  int mid = (l + r) >> 1;
  lc[mid] = build(l, mid - 1, mid);
  rc[mid] = build(mid + 1, r, mid);
  fa[mid] = f;
  sz[mid] = r - l + 1;
  return mid;
}
char s[MAXK + 10], ans[MAXK + 10], tmp[MAXN + 10];
int lcut[MAXN + 10], rcut[MAXN + 10];
void get2(int u, vector<int>& vec) {
  if (lc[u]) get2(lc[u], vec);
  vec.push_back(u);
  if (rc[u]) get2(rc[u], vec);
}
int getpos(int p) {
  int u = rt;
  while (u) {
    int mid = sz[lc[u]] + 1;
    if (p == mid) return u;
    if (p < mid)
      u = lc[u];
    else
      p -= mid, u = rc[u];
  }
  return 0;
}
int getseq(int l, int r) {
  if (l == 1 && r == sz[rt]) return rt;
  if (l == 1) {
    splay(getpos(r + 1));
    return lc[rt];
  }
  if (r == sz[rt]) {
    splay(getpos(l - 1));
    return rc[rt];
  }
  splay(getpos(l - 1));
  splay(getpos(r + 1), rt);
  return lc[rc[rt]];
}
void del(int l, int r) {
  if (r == sz[rt]) {
    int u = getpos(l - 1);
    splay(u);
    rc[u] = 0;
    update(u);
  } else {
    int u = getpos(l - 1);
    splay(u);
    int v = getpos(r + 1);
    splay(v, u);
    lc[v] = 0;
    update(v);
    update(u);
  }
}
bool flag = 0;
void get1(int u, vector<int>& vec0, vector<int>& vec1) {
  if (lc[u]) get1(lc[u], vec0, vec1);
  if (flag)
    vec1.push_back(u);
  else
    vec0.push_back(u);
  flag ^= 1;
  if (rc[u]) get1(rc[u], vec0, vec1);
}
void get0(int u, vector<int>& vec, int nd) {
  if (lc[u]) get0(lc[u], vec, nd);
  if (vec.size() == nd) return;
  if (!flag) vec.push_back(u);
  flag ^= 1;
  if (vec.size() == nd) return;
  if (rc[u]) get0(rc[u], vec, nd);
}
void solve(int k, int n) {
  if (!n) {
    vector<int> vec;
    get2(rt, vec);
    for (int i = 0; i < vec.size(); ++i) ans[vec[i]] = s[i + 1];
    return;
  }
  int l = lcut[n], r = rcut[n];
  if (r >= sz[rt]) return solve(k, n - 1);
  vector<int> vec0, vec1, vec2;
  if (r + r - l + 1 >= sz[rt]) {
    flag = 1;
    int num = k - r;
    if (num <= r / 2 - l / 2)
      get0(getseq(l, r), vec0, num);
    else {
      get1(getseq(l, r), vec0, vec1);
      num -= vec0.size();
      for (int i = 0; i < num; ++i) vec0.push_back(vec1[i]);
    }
    get2(getseq(r + 1, sz[rt]), vec2);
    del(r + 1, sz[rt]);
    solve(r, n - 1);
  } else {
    flag = 1;
    get1(getseq(l, r), vec0, vec1);
    for (int i = 0; i < vec1.size(); ++i) vec0.push_back(vec1[i]);
    get2(getseq(r + 1, 2 * r - l + 1), vec2);
    del(r + 1, 2 * r - l + 1);
    solve(k - (r - l + 1), n - 1);
  }
  for (int i = 0; i < vec2.size(); ++i) ans[vec2[i]] = ans[vec0[i]];
}
int main() {
  scanf("%s", s + 1);
  int k = getint(), n = getint();
  for (int i = 1; i <= n; ++i) lcut[i] = getint(), rcut[i] = getint();
  rt = build(1, k, 0);
  solve(k, n);
  printf("%s", ans + 1);
  return 0;
}