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>
using namespace std;
const int maxn = 3000010;
char S[maxn], T[maxn];
int ans[maxn];
struct Tnode {
  int s, x;
  Tnode *l, *r;
  Tnode *prev, *succ, *tl, *tr;
  Tnode();
};
Tnode *tp;
Tnode::Tnode() : r(tp) { tp = this; }
inline Tnode *newnode() {
  if (!tp) new Tnode[10000];
  Tnode *ret = tp;
  return tp = tp->r, ret;
}
inline Tnode *getnew(int x) {
  Tnode *ret = newnode();
  return ret->s = 1, ret->x = x, ret->prev = ret->succ = 0,
         ret->tl = ret->tr = ret, ret;
}
inline Tnode *getnew(Tnode *a, Tnode *b) {
  Tnode *ret = newnode();
  return ret->s = a->s + b->s, ret->l = a, ret->r = b, ret->tl = a->tl,
         ret->tr = b->tr, a->tr->succ = b->tl, b->tl->prev = a->tr, ret;
}
inline void drop(Tnode *R) {
  if (R->s > 1) R->l->tr->succ = R->r->tl->prev = 0;
  R->r = tp, tp = R;
}
Tnode *merge(Tnode *a, Tnode *b) {
  if (!a || !b) return a ? a : b;
  if (((a->s) << 1) >= b->s && ((b->s) << 1) >= a->s) return getnew(a, b);
  if (a->s < b->s) {
    Tnode *c = b->l, *d = b->r, *e, *f;
    drop(b);
    if (((d->s) << 1) >= a->s + c->s) return getnew(merge(a, c), d);
    return e = c->l, f = c->r, drop(c), merge(merge(a, e), merge(f, d));
  } else {
    Tnode *c = a->r, *d = a->l, *e, *f;
    drop(a);
    if (((d->s) << 1) >= c->s + b->s) return getnew(d, merge(c, b));
    return f = c->l, e = c->r, drop(c), merge(merge(d, f), merge(e, b));
  }
}
void split(Tnode *R, int k, Tnode *&x, Tnode *&y) {
  if (!k)
    x = 0, y = R;
  else if (k == R->s)
    x = R, y = 0;
  else {
    Tnode *a = R->l, *b = R->r;
    drop(R);
    if (k <= a->s)
      split(a, k, x, a), y = merge(a, b);
    else
      split(b, k - a->s, b, y), x = merge(a, b);
  }
}
Tnode *build(int l, int r) {
  if (l == r) return getnew(l);
  int mid = (l + r) >> 1;
  return getnew(build(l, mid), build(mid + 1, r));
}
int m;
Tnode *R;
int Q;
pair<int, int> Qs[5010];
void droptree(Tnode *R) {
  if (R->s > 1) {
    Tnode *a = R->l, *b = R->r;
    drop(R);
    droptree(a), droptree(b);
  } else
    drop(R);
}
void remove(int l, int r) {
  Tnode *a, *b, *c;
  split(R, l - 1, a, b);
  split(b, r - l + 1, b, c);
  droptree(b);
  R = merge(a, c);
}
Tnode *getkth(Tnode *R, int k) {
  if (R->s == 1) return R;
  if (k <= R->l->s) return getkth(R->l, k);
  return getkth(R->r, k - R->l->s);
}
int main() {
  scanf("%s%d", S + 1, &m);
  R = build(1, m);
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    Qs[i] = make_pair(l, r);
  }
  for (int ii = Q; ii; ii--) {
    int l = Qs[ii].first, r = Qs[ii].second;
    if (r >= R->s) continue;
    int len = min(r - l + 1, R->s - r);
    Tnode *pl = getkth(R, l), *pl1 = pl->succ, *pr = getkth(R, r),
          *pr1 = pr->succ;
    int r1 = pr1->x;
    Tnode *i = pl1->x >= r1 ? pl : pl1, *j = pr1;
    int iii = 1;
    for (;;) {
      if (iii > len) break;
      ans[j->x] = i->x;
      j = j->succ;
      if (i == pr)
        i = pl;
      else {
        i = i->succ->succ;
        if (i->x >= r1) i = pl;
      }
      iii++;
    }
    remove(r + 1, r + len);
  }
  Tnode *p = R->tl;
  for (int i = 1; i <= R->s; i++, p = p->succ) T[p->x] = S[i];
  for (int i = 1; i <= m; i++)
    if (ans[i]) T[i] = T[ans[i]];
  puts(T + 1);
  return 0;
}