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 JAVA):

Solution:
import java.io.*;
import java.lang.reflect.*;
import java.util.*;

public class B {

	final int MOD = 1000000007;
	final double eps = 1e-12;
	final int INF = (int)1e9;
	
	public B () throws Exception {
		int N = sc.nextInt();
		int Q = sc.nextInt();
		char [] prog = sc.nextChars();
		for (int q = 0; q < Q; ++q) {
			int L = sc.nextInt() - 1;
			int R = sc.nextInt();
			List<Character> P = new ArrayList<Character>();
			for (int i = L; i < R; ++i)
				P.add(prog[i]);
			int [] CNT = new int [10];
			int CP = 0, DP = 1;
			while (CP >= 0 && CP < P.size()) {
				switch (P.get(CP)) {
				case '<': {
					int NCP = CP - 1; DP = -1;
					if (NCP >= 0)
						if (P.get(NCP) == '<' || P.get(NCP) == '>') {
							P.remove(CP);
						}
					CP = NCP;
					break;
				}
				case '>': {
					int NCP = CP + 1; DP = 1;
					if (NCP < P.size())
						if (P.get(NCP) == '<' || P.get(NCP) == '>') {
							P.remove(CP); 
							--NCP;
						}
					CP = NCP;
					break;
				}
				case '0': {
					++CNT[0];
					int NCP = CP + DP;
					P.remove(CP);
					if (DP == 1)
						--NCP;
					CP = NCP;
					break;
				}
				default: {
					++CNT[P.get(CP) - '0'];
					P.set(CP, (char)(P.get(CP) - 1));
					CP += DP;
				}
				}
			}
			print(CNT);
		}
	}

	////////////////////////////////////////////////////////////////////////////////////
	
	static MyScanner sc;
	
	static class MyScanner {
		public String next() throws Exception {
			newLine();
			return line[index++];
		}
		
		public char nextChar() throws Exception {
			return next().charAt(0);
		}
				
		public int nextInt() throws Exception {
			return Integer.parseInt(next());
		}
		
		public long nextLong() throws Exception {
			return Long.parseLong(next());
		}
		
		public double nextDouble() throws Exception {
			return Double.parseDouble(next());
		}
		
		public String nextLine() throws Exception {
			line = null;
			return r.readLine();
		}
		
		public String [] nextStrings() throws Exception {
			line = null;
			return r.readLine().split(" ");
		}
		
		public char [] nextChars() throws Exception {
			return next().toCharArray();
		}

		public Integer [] nextInts() throws Exception {
			String [] L = nextStrings();
			Integer [] res = new Integer [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Integer.parseInt(L[i]);
			return res;
		}	
		
		public Long [] nextLongs() throws Exception {
			String [] L = nextStrings();
			Long [] res = new Long [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Long.parseLong(L[i]);
			return res;
		}

		public Double [] nextDoubles() throws Exception {
			String [] L = nextStrings();
			Double [] res = new Double [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Double.parseDouble(L[i]);
			return res;
		}

		boolean eol() {
			return index == line.length;
		}

		//////////////////////////////////////////////
		
		private final BufferedReader r;

		MyScanner () throws Exception {
			this(new BufferedReader(new InputStreamReader(System.in)));
		}
		
		MyScanner(BufferedReader r) throws Exception { 
			this.r = r;
			while (!r.ready())
				Thread.sleep(1);
			start();
		}
		
		private String [] line;
		private int index;

		private void newLine() throws Exception {
			if (line == null || eol()) {
				line = r.readLine().split(" ");
				index = 0;
			}
		}		
	}
	
	static void print (Object... a) {
		pw.println(build(a));
	}

	static void exit (Object... a) {
		print(a);
		exit();
	}

	static void exit () {
		pw.close();
		System.out.flush();
		System.err.println("------------------");
		System.err.println("Time: " + ((millis() - t) / 1000.0));
		System.exit(0);
	}
	
	void NO() {
		throw new Error("NO!");
	}
	
	////////////////////////////////////////////////////////////////////////////////////
	
	static void append(StringBuilder b, Object o) {
		if (o.getClass().isArray()) {
			int L = Array.getLength(o);
			for (int i = 0; i < L; ++i)
				append(b, Array.get(o, i));
		} else if (o instanceof Iterable<?>) {
			for (Object p : (Iterable<?>)o)
				append(b, p);
		} else
			b.append(" ").append(o);		
	}
	
	static String build(Object... a) {
		StringBuilder b = new StringBuilder();
		for (Object o : a)
			append(b, o);
		return b.toString().trim();		
	}
	
	////////////////////////////////////////////////////////////////////////////////////
	
	public static void main(String[] args) throws Exception {
		sc = new MyScanner ();
		new B();
		exit();
	}

	static void start() {
		t = millis();
	}

	static PrintWriter pw = new PrintWriter(System.out);
	
	static long t;
	
	static long millis() {
		return System.currentTimeMillis();
	}	
}