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, maxm = 5010;
int n, k, tot;
int l[maxm], r[maxm];
char s[maxn];
struct pt {
  pt *c[2], *f;
  int s;
  bool d;
  char w;
} Tnil, *nil, pool[maxn], *R;
inline void sc(pt *x, pt *y, const bool &d) {
  x->c[d] = y;
  if (y != nil) y->f = x, y->d = d;
}
inline void rot(pt *x) {
  pt *y = x->f;
  bool d = x->d;
  sc(y, x->c[!d], d);
  if (y->f != nil)
    sc(y->f, x, y->d);
  else
    x->f = nil, R = x;
  sc(x, y, !d);
  y->s = y->c[0]->s + y->c[1]->s + 1;
  x->s = x->c[0]->s + x->c[1]->s + 1;
}
inline void spl(pt *x, pt *y) {
  while (x->f != y)
    if (x->f->f == y)
      rot(x);
    else
      (x->d ^ x->f->d) ? (rot(x), rot(x)) : (rot(x->f), rot(x));
}
inline pt *sel(int k) {
  for (pt *x = R; x != nil;)
    if (k == x->c[0]->s + 1)
      return x;
    else if (k <= x->c[0]->s)
      x = x->c[0];
    else
      k = k - x->c[0]->s - 1, x = x->c[1];
  return nil;
}
int M, m, L;
char b[maxn];
pt *dump(char *s, int n) {
  pt *a = pool + tot;
  tot += n, s--;
  for (int i = n; i; --i) {
    a[i] = Tnil;
    if (i != n) sc(a + i, a + i + 1, 1);
    a[i].w = s[i], a[i].s = n - i + 1;
  }
  return a + 1;
}
inline void trv_s(pt *x, bool w) {
  if (x == nil || M == L) return;
  trv_s(x->c[0], w);
  if (M == L) return;
  if (++m, (m & 1) == w) b[M++] = x->w;
  trv_s(x->c[1], w);
}
inline void trv_c(pt *x) {
  if (x == nil) return;
  trv_c(x->c[0]);
  if (x->w) fprintf(stderr, "%c", x->w);
  trv_c(x->c[1]);
}
void sol(int n, int k) {
  if (!n) {
    sc(pool + 1, dump(s, k), 0);
    pool->s += k, (pool + 1)->s += k;
    return;
  }
  int l = ::l[n], r = ::r[n],
      w = max(0, min(2 * r - l + 1, k) - max(r + 1, 1) + 1);
  sol(n - 1, k - w);
  if (!w) return;
  pt *u = sel(l), *v = sel(r + 2);
  spl(u, nil), spl(v, u);
  M = 0, L = w;
  m = 0, trv_s(v->c[0], 0);
  m = 0, trv_s(v->c[0], 1);
  u = sel(r + 1), v = sel(r + 2);
  spl(u, nil), spl(v, u);
  sc(v, dump(b, M), 0);
  u->s += M, v->s += M;
}
inline void trv(pt *x) {
  if (x == nil) return;
  trv(x->c[0]);
  b[m++] = x->w;
  trv(x->c[1]);
}
int main() {
  gets(s);
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= n; ++i) scanf("%d%d", l + i, r + i);
  Tnil.s = 0, Tnil.c[0] = Tnil.c[1] = nil = &Tnil;
  pt *u = pool, *v = pool + 1;
  *u = *v = Tnil, u->f = nil, v->s = 1, u->s = 2;
  sc(u, v, 1);
  R = u, tot = 1;
  sol(n, k);
  u = pool, v = sel(k + 2);
  spl(u, nil), spl(v, u);
  m = 0, trv(v->c[0]);
  b[m] = 0, puts(b);
  return 0;
}