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 Data {
  int Pos, Number;
};
bool operator<(Data A, Data B) { return A.Pos > B.Pos; }
int Get() {
  char c;
  while (c = getchar(), c < '0' || c > '9')
    ;
  int X = 0;
  while (c >= '0' && c <= '9') {
    X = X * 10 + c - 48;
    c = getchar();
  }
  return X;
}
int GetTape() {
  char c;
  while (c = getchar(), (c < '0' || c > '9') && (c != '<') && (c != '>'))
    ;
  if (c >= '0' && c <= '9') return c - 48;
  return (c == '<') ? -1 : -2;
}
const int inf = 1000000000;
int N;
int Tape[100002];
vector<Data> Q[100001];
set<int> AllPos;
bool Flag[100001], Out[100000];
int Sum[10], Ans[100000][10];
int Next(set<int>::iterator P, int Direction) {
  return *((Direction == 1) ? (++P) : (--P));
}
int Work(set<int>::iterator P, int Low) {
  int Direction = 1;
  static Data Stack[100000];
  int Top = 0, Far = Low;
  priority_queue<Data> Queue;
  while (true) {
    Far = max(Far, *P);
    if (*P > Low && *P <= N && !Flag[*P]) {
      for (int i = 0; i < Q[*P].size(); i++) {
        for (int j = 0; j < 10; j++) Ans[Q[*P][i].Number][j] = -Sum[j];
        Stack[Top++] = (Data){*P, Q[*P][i].Number};
        Queue.push((Data){Q[*P][i].Pos, Q[*P][i].Number});
      }
      Flag[*P] = true;
    }
    while (Top && *P < Stack[Top - 1].Pos) {
      Top--;
      int V = Stack[Top].Number;
      if (Out[V]) continue;
      Out[V] = true;
      for (int i = 0; i < 10; i++) Ans[V][i] += Sum[i];
    }
    while (!Queue.empty() && *P > Queue.top().Pos) {
      int V = Queue.top().Number;
      Queue.pop();
      if (Out[V]) continue;
      Out[V] = true;
      for (int i = 0; i < 10; i++) Ans[V][i] += Sum[i];
    }
    if (*P <= Low || *P > N) break;
    if (Tape[*P] >= 0) {
      Sum[Tape[*P]]++;
      int Q = Next(P, Direction);
      Tape[*P]--;
      if (Tape[*P] < 0) AllPos.erase(P);
      P = AllPos.find(Q);
    } else {
      Direction = (Tape[*P] == -1) ? -1 : 1;
      int Q = Next(P, Direction);
      if (Tape[Q] < 0) AllPos.erase(P);
      P = AllPos.find(Q);
    }
  }
  return Far;
}
int main() {
  N = Get();
  int M = Get();
  for (int i = 1; i <= N; i++) Tape[i] = GetTape();
  for (int i = 0; i < M; i++) {
    int L = Get(), R = Get();
    Q[L].push_back((Data){R, i});
  }
  for (int i = 0; i <= N + 1; i++) AllPos.insert(i);
  memset(Flag, 0, sizeof(Flag));
  memset(Out, 0, sizeof(Out));
  memset(Sum, 0, sizeof(Sum));
  memset(Ans, 0, sizeof(Ans));
  int Max = 0;
  while (Max < N) Max = Work(AllPos.find(Max + 1), Max);
  for (int i = 0; i < M; i++)
    for (int j = 0; j < 10; j++) {
      printf("%d", Ans[i][j]);
      putchar((j == 9) ? '\n' : ' ');
    }
  return 0;
}