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;
int infinito = 1000000000;
int main() {
  int n, q;
  cin >> n >> q;
  vector<int> v(n + 2);
  v[0] = v[n + 1] = infinito;
  for (int i = 1; i <= n; i++) {
    char c;
    cin >> c;
    if (c == '<')
      v[i] = -9;
    else if (c == '>')
      v[i] = -10;
    else
      v[i] = c - '0';
  }
  vector<int> visto(n + 2, 0);
  vector<int> cuantos(10, 0);
  vector<vector<int> > derecha(n + 2);
  vector<vector<int> > izquierda(n + 2);
  vector<int> hecho(q, 0);
  vector<vector<int> > resultado(q, vector<int>(10));
  for (int i = 0; i < q; i++) {
    int le, ri;
    cin >> le >> ri;
    izquierda[le].push_back(i);
    derecha[ri].push_back(i);
  }
  list<int> l;
  for (int i = 0; i <= n + 1; i++) l.push_back(i);
  int numelems = n;
  while (numelems > 0) {
    list<int>::iterator it = l.begin();
    int dir = 1;
    int lastpos = -1;
    for (;;) {
      int pos = *it;
      visto[pos] = 1;
      if (v[pos] >= -8) {
        if (v[pos] >= 0 and v[pos] < 10) {
          cuantos[v[pos]]++;
          lastpos = pos;
        }
        if (v[pos] < 10) v[pos]--;
        if (v[pos] < -2) {
          it = l.erase(it);
          numelems--;
          if (dir == -1) it--;
        } else {
          if (dir == 1)
            it++;
          else
            it--;
        }
      } else if (v[pos] == -9) {
        if (lastpos != -1 and (v[lastpos] == -9 or v[lastpos] == -10))
          v[lastpos] = -1;
        lastpos = pos;
        dir = -1;
        it--;
      } else if (v[pos] == -10) {
        if (lastpos != -1 and (v[lastpos] == -9 or v[lastpos] == -10))
          v[lastpos] = -1;
        lastpos = pos;
        dir = 1;
        it++;
      }
      pos = *it;
      visto[pos] = 1;
      if (int(izquierda[pos].size()) > 0 and hecho[izquierda[pos][0]] == 0) {
        vector<int> &iz = izquierda[pos];
        for (int i = 0; i < int(iz.size()); i++) {
          int que = iz[i];
          for (int j = 0; j < 10; j++) resultado[que][j] = cuantos[j];
          hecho[que] = 1;
        }
      }
      if (dir == 1 and int(derecha[pos - 1].size()) > 0) {
        while (int(derecha[pos - 1].size()) > 0) {
          int que = derecha[pos - 1].back();
          derecha[pos - 1].pop_back();
          if (hecho[que] == 1) {
            for (int j = 0; j < 10; j++)
              resultado[que][j] = cuantos[j] - resultado[que][j];
            hecho[que] = 2;
          }
        }
      }
      if (dir == -1 and int(izquierda[pos + 1].size()) > 0) {
        while (int(izquierda[pos + 1].size()) > 0) {
          int que = izquierda[pos + 1].back();
          izquierda[pos + 1].pop_back();
          if (hecho[que] == 1) {
            for (int j = 0; j < 10; j++)
              resultado[que][j] = cuantos[j] - resultado[que][j];
            hecho[que] = 2;
          }
        }
      }
      if (pos == 0 or pos == n + 1) break;
    }
    it = l.begin();
    it++;
    while (*it != n + 1 and visto[(*it) + 1]) {
      it = l.erase(it);
      numelems--;
    }
    v[*it] = -1;
  }
  for (int i = 0; i < q; i++) {
    vector<int> &r = resultado[i];
    for (int j = 0; j < int(r.size()); j++) {
      if (j > 0) cout << " ";
      cout << r[j];
    }
    cout << endl;
  }
}