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;
inline long long rd() {
  long long _x = 0;
  int _ch = getchar(), _f = 1;
  for (; !isdigit(_ch) && (_ch != '-') && (_ch != EOF); _ch = getchar())
    ;
  if (_ch == '-') {
    _f = 0;
    _ch = getchar();
  }
  for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch - '0';
  return _f ? _x : -_x;
}
void write(long long _x) {
  if (_x >= 10)
    write(_x / 10), putchar(_x % 10 + '0');
  else
    putchar(_x + '0');
}
inline void wrt(long long _x, char _p) {
  if (_x < 0) putchar('-'), _x = -_x;
  write(_x);
  if (_p) putchar(_p);
}
char s[1000005];
int n, Q;
int sta[1000005], top, tot;
pair<int, int> H[1000005];
struct node {
  int v[10];
  node operator+(const node &B) const {
    node ans;
    for (int i = int(0); i <= (int)(9); i++) ans.v[i] = v[i] + B.v[i];
    return ans;
  }
  node operator-(const node &B) const {
    node ans;
    for (int i = int(0); i <= (int)(9); i++) ans.v[i] = v[i] - B.v[i];
    return ans;
  }
} T[1000005], cnt;
int nx[1000005][2];
void erase(int x) {
  nx[nx[x][0]][1] = nx[x][1];
  nx[nx[x][1]][0] = nx[x][0];
}
vector<int> pass[1000005];
int t;
int fr[1000005];
bool solve() {
  for (int pos = nx[0][1], k = 1;; pos = nx[pos][k]) {
    T[++t] = cnt;
    if (pass[pos].empty()) fr[pos] = nx[pos][0];
    pass[pos].push_back(t);
    if (!pos) return 0;
    if (pos > n) return 1;
    if (s[pos] == '<' || s[pos] == '>') {
      k = s[pos] == '<' ? 0 : 1;
      if (!nx[pos][k] || s[nx[pos][k]] == '<' || s[nx[pos][k]] == '>')
        erase(pos);
    } else {
      cnt.v[s[pos] - '0']++, s[pos]--;
      if (s[pos] < '0') erase(pos);
    }
  }
}
int find(int x, int t) {
  vector<int>::iterator it = lower_bound(pass[x].begin(), pass[x].end(), t);
  if (it == pass[x].end())
    return 1e9;
  else
    return *it;
}
int main() {
  n = rd();
  Q = rd();
  scanf("%s", s + 1);
  for (int i = int(0); i <= (int)(n); i++) nx[i][1] = i + 1, nx[i + 1][0] = i;
  int total = 0;
  while (!solve()) {
  }
  for (int i = int(1); i <= (int)(Q); i++) {
    int l = rd(), r = rd();
    int T1 = pass[l][0];
    int T2 = min(find(fr[l], T1), find(r + 1, T1));
    node ans = T[T2] - T[T1];
    for (int j = int(0); j <= (int)(9); j++) wrt(ans.v[j], ' ');
    putchar('\n');
  }
}