Problem: There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts.

  * Current character pointer (CP); 
  * Direction pointer (DP) which can point left or right; 



Initially CP points to the leftmost character of the sequence and DP points to the right.

We repeat the following steps until the first moment that CP points to somewhere outside the sequence.

  * If CP is pointing to a digit the interpreter prints that digit then CP moves one step according to the direction of DP. After that the value of the printed digit in the sequence decreases by one. If the printed digit was 0 then it cannot be decreased therefore it's erased from the sequence and the length of the sequence decreases by one. 
  * If CP is pointing to "<" or ">" then the direction of DP changes to "left" or "right" correspondingly. Then CP moves one step according to DP. If the new character that CP is pointing to is "<" or ">" then the previous character will be erased from the sequence. 



If at any moment the CP goes outside of the sequence the execution is terminated.

It's obvious the every program in this language terminates after some steps.

We have a sequence s1, s2, ..., sn of "<", ">" and digits. You should answer q queries. Each query gives you l and r and asks how many of each digit will be printed if we run the sequence sl, sl + 1, ..., sr as an independent program in this language.

Input

The first line of input contains two integers n and q (1 ≤ n, q ≤ 105) — represents the length of the sequence s and the number of queries. 

The second line contains s, a sequence of "<", ">" and digits (0..9) written from left to right. Note, that the characters of s are not separated with spaces. 

The next q lines each contains two integers li and ri (1 ≤ li ≤ ri ≤ n) — the i-th query.

Output

For each query print 10 space separated integers: x0, x1, ..., x9 where xi equals the number of times the interpreter prints i while running the corresponding program. Print answers to the queries in the order they are given in input.

Examples

Input

7 4
1&gt;3&gt;22&lt;
1 3
4 7
7 7
1 7


Output

0 1 0 1 0 0 0 0 0 0
2 2 2 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
2 3 2 1 0 0 0 0 0 0

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct node {
  int s[10];
};
pair<int, int> sta[100001];
struct seg {
  int l, r, val;
} t[400100];
struct que {
  int l, r, po;
} q[100010];
bool cmp(que a, que b) { return a.r < b.r; }
node s[100010], laz, sum0[100010], sum1[100010], ans[100010];
int n, Q, nxt[100010], la[100010], f[100010][18], o[21], oN, lo[100010], tp, L,
    R, Mid, Ans;
char str[100010];
node operator+(node A, node B) {
  for (int i = 0; i < 10; i++) A.s[i] += B.s[i];
  return A;
}
node operator-(node A, node B) {
  for (int i = 0; i < 10; i++) A.s[i] -= B.s[i];
  return A;
}
int getmax(int l, int r) {
  int len = lo[r - l + 1];
  return max(f[l][len], f[r - (1 << len) + 1][len]);
}
void build(int i, int l, int r) {
  t[i].l = l, t[i].r = r, t[i].val = n + 1;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(i << 1, l, mid), build(i << 1 | 1, mid + 1, r);
}
int query(int i, int l, int r) {
  if (t[i].l == l && t[i].r == r) return t[i].val;
  int mid = (t[i].l + t[i].r) >> 1;
  if (r <= mid) return query(i << 1, l, r);
  if (l > mid) return query(i << 1 | 1, l, r);
  return min(query(i << 1, l, mid), query(i << 1 | 1, mid + 1, r));
}
void change(int i, int x, int v) {
  if (t[i].l == t[i].r) {
    t[i].val = v;
    return;
  }
  int mid = (t[i].l + t[i].r) >> 1;
  if (x <= mid)
    change(i << 1, x, v);
  else
    change(i << 1 | 1, x, v);
  t[i].val = min(t[i << 1].val, t[i << 1 | 1].val);
}
int find(int i, int l, int v) {
  if (t[i].l == t[i].r) return t[i].l;
  int mid = (t[i].l + t[i].r) >> 1;
  if (l > mid) return find(i << 1 | 1, l, v);
  if (query(i, l, mid) < v)
    return find(i << 1, l, v);
  else
    return find(i << 1 | 1, mid + 1, v);
}
void print(int x) {
  if (!x)
    putchar('0');
  else {
    oN = 0;
    while (x) o[++oN] = x % 10, x /= 10;
    for (int i = oN; i; i--) putchar(o[i] + 48);
  }
  putchar(' ');
}
int main() {
  lo[1] = 0;
  for (int i = 2; i <= 100000; i++) lo[i] = lo[i >> 1] + 1;
  scanf("%d%d", &n, &Q), scanf("%s", str + 1);
  la[0] = 0;
  for (int i = 1; i <= n; i++)
    if (str[i] == '<' || str[i] == '>')
      la[i] = i;
    else
      la[i] = la[i - 1];
  nxt[n + 1] = n + 1;
  for (int i = n; i; i--)
    if (str[i] == '<' || str[i] == '>')
      nxt[i] = i;
    else
      nxt[i] = nxt[i + 1];
  for (int i = 1; i <= n; i++)
    if (str[i] == '<' || str[i] == '>')
      f[i][0] = -1;
    else
      f[i][0] = str[i] - '0';
  for (int j = 1; j <= 17; j++)
    for (int i = 1; i <= n; i++)
      if (i + (1 << j) <= n + 1)
        f[i][j] = max(f[i][j - 1], f[i + (1 << j - 1)][j - 1]);
  memset(sum0, 0, sizeof(sum0));
  memset(sum1, 0, sizeof(sum1));
  for (int i = 1; i <= n; i++) {
    sum0[i] = sum0[i - 1], sum1[i] = sum1[i - 1];
    if (str[i] >= '0' && str[i] <= '9') {
      sum0[i].s[str[i] - '0']++;
      if (str[i] != '0') sum1[i].s[str[i] - '1']++;
    }
  }
  build(1, 1, n);
  for (int i = 1; i <= Q; i++) scanf("%d%d", &q[i].l, &q[i].r), q[i].po = i;
  sort(q + 1, q + 1 + Q, cmp), tp = 0;
  memset(laz.s, 0, sizeof(laz.s));
  memset(s[0].s, 0, sizeof(s[0].s));
  for (int i = 1, po, p, nwq = 1; i <= n; i++) {
    if (str[i] == '<') {
      p = po = la[i - 1];
      while (p) {
        if (str[p] == '<') {
          laz = (laz - (sum1[sta[tp].second] - sum1[sta[tp].first]));
          po = sta[tp].second, p = sta[tp].first, tp--;
          continue;
        }
        if (getmax(po, nxt[po + 1]) & 1)
          po = p = la[p - 1];
        else
          break;
      }
      sta[++tp] = make_pair(p, i);
      laz = (laz + (sum1[i] - sum1[p]));
      s[tp] = ((sum1[i] - sum1[p]) - laz);
      change(1, i, p);
    }
    while (nwq <= Q && q[nwq].r == i) {
      if (query(1, q[nwq].l, q[nwq].r) < q[nwq].l) {
        p = find(1, q[nwq].l, q[nwq].l);
        ans[q[nwq].po] = (sum1[p] - sum1[nxt[q[nwq].l]]);
        for (int i = 8; i >= 0; i--)
          ans[q[nwq].po].s[i] += ans[q[nwq].po].s[i + 1];
        ans[q[nwq].po] = (ans[q[nwq].po] + (sum0[p] - sum0[q[nwq].l - 1]));
        ans[q[nwq].po] =
            (ans[q[nwq].po] + (sum1[nxt[q[nwq].l]] - sum1[q[nwq].l - 1]));
      } else {
        L = 1, R = tp, Ans = 0;
        while (L <= R) {
          Mid = (L + R) >> 1;
          if (sta[Mid].second >= q[nwq].l)
            Ans = Mid, R = Mid - 1;
          else
            L = Mid + 1;
        }
        if (Ans) {
          ans[q[nwq].po] = (s[Ans] + laz);
          for (int i = 8; i >= 0; i--)
            ans[q[nwq].po].s[i] += ans[q[nwq].po].s[i + 1];
          ans[q[nwq].po] = (ans[q[nwq].po] + (sum0[i] - sum0[q[nwq].l - 1]));
        } else
          ans[q[nwq].po] = (sum0[i] - sum0[q[nwq].l - 1]);
      }
      nwq++;
    }
  }
  for (int i = 1; i <= Q; i++, putchar('\n'))
    for (int j = 0; j < 10; j++) print(ans[i].s[j]);
  return 0;
}