#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
#define N 1100
#define clr(a) memset(a,0,sizeof(a))
#define F(i,a,n) for(int i=a;i<=n;i++)
char t[N];
int m;
void solve()
{
     /*printf("%d ",m);
       F(i,1,m)
       printf("%c",t[i]);
       */
    int l=1,r=1;
    int num[15];
    clr(num);
    while(1)
    {
        if(l<1||l>m)
            break;
        if(t[l]=='<'||t[l]=='>')
        {
            int ll=l;
            if(t[l]=='<')
                r=-1;
            else
                r=1;
            if(r==1)
                l++;
            else
                l--;
            if(l<1||l>m)
                break;
            if(t[l]=='>'||t[l]=='<')
            {
                t[ll]='a';
            }
            else if(t[l]=='a')
            {
                while(1)
                {
                    if(r==1)
                        l++;
                    else
                        l--;
                    if(l<1||l>m)
                        break;
                    if(t[l]!='a')
                        break;
                }
        if(l<1||l>m)
            break;
                if(t[l]=='>'||t[l]=='<')
                {
                    t[ll]='a';
                }
            }
        }
        else{
                num[t[l]-'0']++;
                if(t[l]>'0'&&t[l]<='9'){
                    t[l]=t[l]-1;
        }
                else
                    t[l]='a';
                if(r==1)
                    l++;
                if(r==-1)
                    l--;
            }
        }
    //F(i,1,m)
    //    printf("%c ",t[i]);
    F(i,0,9)
        printf("%d ",num[i]);
    printf("\n");
    return ;
}
int main()
{
    int n,q;
    char str[N],ss[N];
    while(~scanf("%d%d",&n,&q))
    {
        clr(str);
        scanf("%s",str+1);
    F(i,1,n)
        ss[i]=str[i];

    /*F(i,1,n)
        printf("%c",ss[i]);
    cout<<endl;
        */
    while(q--)
        {
        clr(str);
        F(i,1,n)
        str[i]=ss[i];
           /* printf("%d ",n);
            F(i,1,n)
              printf("%c",str[i]);printf("\n");
            */
          int l,r;
            scanf("%d %d",&l,&r);
            clr(t);
            m=0;
            F(i,l,r)
                t[++m]=str[i];
           solve();
        }
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
#define N 1100
#define clr(a) memset(a,0,sizeof(a))
#define F(i,a,n) for(int i=a;i<=n;i++)
char t[N];
int m;
char str[N];
void solve()
{
    int l=1,r=1;
    int num[15];
    clr(num);
    while(1)
    {
        if(l<1||l>m)
            break;
        if(t[l]=='<'||t[l]=='>')
        {
            int ll=l;
            if(t[l]=='<')
                r=-1;
            else
                r=1;
            if(r==1)
                l++;
            else
                l--;
            if(l<1||l>m)
                break;
            if(t[l]=='>'||t[l]=='<')
            {
                t[ll]='a';
            }
            else if(t[l]=='a')
            {
                while(1)
                {
                    if(r==1)
                        l++;
                    else
                        l--;
                    if(l<1||l>m)
                        break;
                    if(t[l]!='a')
                        break;
                }
                if(l<1||l>m)
                    break;
                if(t[l]=='>'||t[l]=='<')
                {
                    t[ll]='a';
                }
            }
        }
        else{
            num[t[l]-'0']++;
            if(t[l]>'0'&&t[l]<='9'){
                t[l]=t[l]-1;
            }
            else
                t[l]='a';
            if(r==1)
                l++;
            if(r==-1)
                l--;
        }
    }
    F(i,0,9)
        printf("%d ",num[i]);
    printf("\n");
    return ;
}
int main()
{
    int n,q;
    while(~scanf("%d%d",&n,&q))
    {
        clr(str);
        scanf("%s",str+1);
        while(q--)
        {
            int l,r;
            scanf("%d %d",&l,&r);
            clr(t);
            m=0;
            F(i,l,r)
                t[++m]=str[i];
            solve();
        }
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
#define N 1100
#define clr(a) memset(a,0,sizeof(a))
#define F(i,a,n) for(int i=a;i<=n;i++)
char t[N];
int m;

void solve()
{
    int l=1,r=1;
    int num[15];
    clr(num);
    while(1)
    {
        if(l<1||l>m)
            break;
        if(t[l]=='<'||t[l]=='>')
        {
            int ll=l;
            if(t[l]=='<')
                r=-1;
            else
                r=1;
            if(r==1)
                l++;
            else
                l--;
            if(l<1||l>m)
                break;
            if(t[l]=='>'||t[l]=='<')
            {
                t[ll]='a';
            }
            else if(t[l]=='a')
            {
                while(1)
                {
                    if(r==1)
                        l++;
                    else
                        l--;
                    if(l<1||l>m)
                        break;
                    if(t[l]!='a')
                        break;
                }
                if(l<1||l>m)
                    break;
                if(t[l]=='>'||t[l]=='<')
                {
                    t[ll]='a';
                }
            }
        }
        else{
            num[t[l]-'0']++;
            if(t[l]>'0'&&t[l]<='9'){
                t[l]=t[l]-1;
            }
            else
                t[l]='a';
            if(r==1)
                l++;
            if(r==-1)
                l--;
        }
    }
    F(i,0,9)
        printf("%d ",num[i]);
    printf("\n");
    return ;
}
int main()
{
    int n,q;
    char ss[N];
    while(~scanf("%d%d",&n,&q))
    {
        clr(ss);
        scanf("%s",ss+1);
        while(q--)
        {
            int l,r;
            scanf("%d %d",&l,&r);
            clr(t);
            m=0;
            F(i,l,r)
                t[++m]=ss[i];
            solve();
        }
    }
    return 0;
}


#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>

using namespace std;

#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)

typedef long long         ll;
const ll OO = 1e8;

#define pb                  push_back
#define MP                  make_pair
#define P(x)                cout<<#x<<" = { "<<x<<" }\n"
#define ff  first
#define ss second
typedef long double       ld;
typedef vector<int>       vi;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);

int a[11] ;
void clc(string s){
    int j  = -1 , f=1  ; int g = 99999 ;
    for(int i=0;i<=s.size()-1&&i>=0&&g--;)
    {
        if(s[i]=='*')  { (f)? i+=1:i-=1 ; continue ; }
        if(s[i]=='>')  { f=1,i+=1 ; if((s[j]=='>'||s[j]=='<')&&(i-1!=j)) s[j]='*' ; }
        else if(s[i]=='<')  { f=0,i-=1 ; if((s[j]=='>'||s[j]=='<')&&(i+1!=j)) s[j]='*' ; }
        else {  a[s[i]-'0']+=1 ;
            s[i]-=1 ;
            if(s[i]<'0') s[i]='*' ;
            (f)? i+=1:i-=1 ;
        }
       // cout<<s<<" "<<j<<endl ;
        j = i  ;
    }

}

int main ()
{
    int n, q ;
    cin>>n>>q ;
    string s ;
    cin>>s ;
    int l , r ;
    while (q--) {
        cin>>l>>r ;
        clr(a,0) ;
        clc(s.substr(l-1,(r-l+1))) ;
        for(int i=0;i<10;i++)
            cout<<a[i]<<" " ;
        cout<<endl ;
    }
}


#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>

using namespace std;

#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)

typedef long long         ll;
const ll OO = 1e8;

#define pb                  push_back
#define MP                  make_pair
#define P(x)                cout<<#x<<" = { "<<x<<" }\n"
#define ff  first
#define ss second
typedef long double       ld;
typedef vector<int>       vi;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);

int a[11] ;
void clc(string s ){
    int j  , f=1  ;
    for(int i=0;i<=s.size()-1&&i>=0&&s.size()!=0;)
    {
        j=i ;
        if(s[i]=='>') i+=1,f=1 ;
        else if(s[i]=='<') i-=1,f=0 ;
        else a[s[i]-'0']+=1,s[i]-=1,(f)? i+=1 : i-=1 ;
        if(s[i]==47) s.erase(i) ;
        if((s[j]=='<'||s[j]=='>')&&(s[i]=='<'||s[i]=='>')) s.erase(j) ;
        //cout<<s<<endl ;
    }
}
int main ()
{
    int n, q ;
    cin>>n>>q ;
    string s ;
    cin>>s ;
    int l , r ;
    while (q--) {
        cin>>l>>r ;
        clr(a,0) ;
        clc(s.substr(l-1,(r-l+1))) ;
        for(int i=0;i<10;i++)
            cout<<a[i]<<" " ;
        cout<<endl ;
    }

}


#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>

using namespace std;

#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)

typedef long long         ll;
const ll OO = 1e8;

#define pb                  push_back
#define MP                  make_pair
#define P(x)                cout<<#x<<" = { "<<x<<" }\n"
#define ff  first
#define ss second
typedef long double       ld;
typedef vector<int>       vi;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);

int a[11] ;
void clc(string s ){
    int j  , f=1  ;
    for(int i=0;i<=s.size()-1&&i>=0&&s.size()!=0;)
    {
        j=i ;
        if(s[i]=='>') i+=1,f=1 ;
        else if(s[i]=='<') i-=1,f=0 ;
        else  { a[s[i]-'0']+=1,s[i]-=1 ;       if(s[i]==47) s.erase(s.begin()+i) ; else (f)? i+=1 : i-=1 ; }

        if((s[j]=='<'||s[j]=='>')&&(s[i]=='<'||s[i]=='>')) s.erase(s.begin()+j) ;
       // cout<<s<<endl ;
    }
}
int main ()
{
    int n, q ;
    cin>>n>>q ;
    string s ;
    cin>>s ;
    int l , r ;
    while (q--) {
        cin>>l>>r ;
        clr(a,0) ;
        clc(s.substr(l-1,(r-l+1))) ;
        for(int i=0;i<10;i++)
            cout<<a[i]<<" " ;
        cout<<endl ;
    }

}


#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define sz(v)				((int)((v).size()))
#define clr(v, d)			memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)

typedef long long         ll;
const ll OO = 1e8;

#define pb					push_back
#define MP					make_pair
#define P(x)				cout<<#x<<" = { "<<x<<" }\n"
#define ff  first
#define ss second
typedef long double   	  ld;
typedef vector<int>       vi;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);

int a[11] ;
void clc(string s){
    int j  = -1 , f=1  ;
    for(int i=0;i<=s.size()-1&&i>=0;)
    {
        if(s[i]=='*')  { (f)? i+=1:i-=1 ; continue ; }
        if(s[i]=='>')  { f=1,i+=1 ; if((s[j]=='>'||s[j]=='<')&&(i-1!=j)) s[j]='*' ; }
        else if(s[i]=='<')  {   f=0,i-=1 ; if((s[j]=='>'||s[j]=='<')) s[j]='*' ; }
        else {  a[s[i]-'0']+=1 ;
            s[i]-=1 ;
            if(s[i]<'0') s[i]='*' ;
            (f)? i+=1:i-=1 ;
        }
      //  cout<<s<<" "<<j<<endl ;
         j = (f)? i-1:i+1  ;
    }

}

int main ()
{
    int n, q ;
    cin>>n>>q ;
    string s ;
    cin>>s ;
    int l , r ;
    while (q--) {
        cin>>l>>r ;
        clr(a,0) ;
        clc(s.substr(l-1,(r-l+1))) ;
        for(int i=0;i<10;i++)
            cout<<a[i]<<" " ;
        cout<<endl ;
    }
}


#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>

using namespace std;

#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)

typedef long long         ll;
const ll OO = 1e8;

#define pb                  push_back
#define MP                  make_pair
#define P(x)                cout<<#x<<" = { "<<x<<" }\n"
#define ff  first
#define ss second
typedef long double       ld;
typedef vector<int>       vi;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);

int a[11] ;
void clc(string s ){
    int j  , f=1  ;
    for(int i=0;i<=s.size()-1&&i>=0&&s.size()!=0;)
    {
        j=i ;
        if(s[i]=='>') i+=1,f=1 ;
        else if(s[i]=='<') i-=1,f=0 ;
        else  { a[s[i]-'0']+=1,s[i]-=1 ;       if(s[i]==47) { s.erase(s.begin()+i) ; if(!f) i-=1 ;  } else (f)? i+=1 : i-=1 ; }

        if((s[j]=='<'||s[j]=='>')&&(s[i]=='<'||s[i]=='>')) s.erase(s.begin()+j) ;
       // cout<<s<<endl ;
    }
}
int main ()
{
    int n, q ;
    cin>>n>>q ;
    string s ;
    cin>>s ;
    int l , r ;
    while (q--) {
        cin>>l>>r ;
        clr(a,0) ;
        clc(s.substr(l-1,(r-l+1))) ;
        for(int i=0;i<10;i++)
            cout<<a[i]<<" " ;
        cout<<endl ;
    }

}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main () {
	int len,l, r, n, i, j, k, del = 0;
	char *str1;
	scanf("%d %d", &len, &n);
	str1 = (char*)malloc(len);
	scanf("%s", str1);
	for (i = 0; i < n; i++) {
		char *str;
		int A[10], DP = 1, IP=0;
		for(j = 0; j < 10; j++) A[j]=0;
		scanf("%d %d", &l, &r);
		str = (char*)malloc(r-l+2);
		memcpy(str, &(str1[l-1]), r-l+1);
        int len1 = r-l+1;
        str[len1] = 0;
		for(;IP >=0 && IP < len1;) {
		  //  printf("undo str=%s IP=%d(%c)\n", str, IP, str[IP]);
            if (str[IP] >= '0' && str[IP] <= '9') {
                A[(int)str[IP]-(int)'0']++;
                if(str[IP] != '0') (int)(str[IP])--; else str[IP] = del++;

            } else {
                if (str[IP] == '>') {
                    DP = 1;
                    if (IP < len1-1 && (str[IP+1] < '0' && str[IP+1] > '9')) str[IP] = del++;
                } else if (str[IP] == '<') {
                    DP = 0;
                    if (IP >0 && (str[IP-1] < '0' && str[IP-1] > '9')) str[IP] = del++;
                }
            }
            if(del) {
                del =0;
                for(k = 0, j = 0; j < len1; k++, j++) {
                    str[k] = str[j];
                    if(k-IP) k--;
                }
               // str[k]=0;
               // len1--;
            }
            if (DP) IP++; else IP--;
           // printf("redo str=%s IP=%d(%c)\n", str, IP, str[IP]);
		}

		for (j = 0; j < 10; j++) printf("%d ", A[j]);
		printf("\n");
	}
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//18<4229

int main () {
	int len,l, r, n, i, j, k, del = 0;
	char *str1;
	scanf("%d %d", &len, &n);
	str1 = (char*)malloc(len);
	scanf("%s", str1);
	for (i = 0; i < n; i++) {
		char *str;
		int A[10], DP = 1, IP=0;
		for(j = 0; j < 10; j++) A[j]=0;
		scanf("%d %d", &l, &r);
		str = (char*)malloc(r-l+2);
		memcpy(str, &(str1[l-1]), r-l+1);
        int len1 = r-l+1;
        str[len1] = 0;
		for(;IP >=0 && IP < len1;) {
		   // printf("undo str=%s IP=%d(%c)\n", str, IP, str[IP]);
            if (str[IP] >= '0' && str[IP] <= '9') {
                A[(int)str[IP]-(int)'0']++;
                if(str[IP] != '0') (int)(str[IP])--; else del++;

            } else {
                if (str[IP] == '>') {
                    DP = 1;
                    if (IP < len1-1 && (str[IP+1] == '<' || str[IP+1] == '>')) del++;
                } else if (str[IP] == '<') {
                    DP = 0;
                    if (IP >0 && (str[IP-1] == '<' || str[IP-1] == '>')) del++;
                }
            }
            if(del) {
                if (!IP && !DP) break;
                del =0;
                str[IP] = 0;
                for(k = 0, j = 0; k < len1-1; k++, j++) {
                    if(!(k-IP)) {
                        //printf("del(%d)\n", k);
                        j++;
                    }
                    str[k] = str[j];
                }
                len1--;
                str[len1] = 0;
                if (!DP) DP--;
            }else if (DP) IP++; else IP--;
            //printf("redo str=%s IP=%d(%c)\n", str, IP, str[IP]);
		}

		for (j = 0; j < 10; j++) printf("%d ", A[j]);
		printf("\n");
	}
    return 0;
}


#include <iostream>
#include <string>

using namespace std;

void solve(string s) {
	int cp = 0, dp = 1;
	int out[10] = {0};
	while (0 <= cp && cp < s.length()) {
		bool erase = false;
		if ('0' <= s[cp] && s[cp] <= '9') {
			out[s[cp]-'0']++;
			s[cp]--;
			if (s[cp] < '0')
				erase = true;
		} else {
			if (s[cp] == '<')
				dp = -1;
			else
				dp = 1;
			if (cp+dp >= 0 && cp+dp < s.length() && (s[cp+dp] == '<' || s[cp+dp] == '>'))
				erase = true;
		}
		if (erase) {
			s.erase(cp, 1);
			if (dp == -1)
				cp--;
		} else cp += dp;
	}
	for (int i = 0; i < 10; i++)
		cout << out[i] << " ";
	cout << endl;
}

int main() {
	int n, q;
	string s;
	cin >> n >> q;
	cin >> s;
	while (q--) {
		int l, r;
		cin >> l >> r;
		solve(s.substr(l-1, r-l+1));
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main () {
	int len,l, r, n, i, j, k, del = 0;
	char *str1;
	scanf("%d %d", &len, &n);
	str1 = (char*)malloc(len);
	scanf("%s", str1);
	for (i = 0; i < n; i++) {
		char *str;
		int A[10], DP = 1, IP=0;
		for(j = 0; j < 10; j++) A[j]=0;
		scanf("%d %d", &l, &r);
		str = (char*)malloc(r-l+2);
		memcpy(str, &(str1[l-1]), r-l+1);
        int len1 = r-l+1;
        str[len1] = 0;
		for(;IP >=0 && IP < len1;) {
		  //  printf("undo str=%s IP=%d(%c)\n", str, IP, str[IP]);
            if (str[IP] >= '0' && str[IP] <= '9') {
                A[(int)str[IP]-(int)'0']++;
                if(str[IP] != '0') (int)(str[IP])--; else str[IP] = del++;

            } else {
                if (str[IP] == '>') {
                    DP = 1;
                    if (IP < len1-1 && (str[IP+1] < '0' && str[IP+1] > '9')) str[IP] = del++;
                } else if (str[IP] == '<') {
                    DP = 0;
                    if (IP >0 && (str[IP-1] < '0' && str[IP-1] > '9')) str[IP] = del++;
                }
            }
            if(del) {
                del =0;
                for(k = 0, j = 0; j < len1; k++, j++) {
                    str[k] = str[j];
                    if(k-IP) k--;
                }
                //str[k]=0;
                len1--;
            }
            if (DP) IP++; else IP--;
           // printf("redo str=%s IP=%d(%c)\n", str, IP, str[IP]);
		}

		for (j = 0; j < 10; j++) printf("%d ", A[j]);
		printf("\n");
	}
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main () {
	int len,l, r, n, i, j, k, del = 0;
	char *str1;
	scanf("%d %d", &len, &n);
	str1 = (char*)malloc(len);
	scanf("%s", str1);
	for (i = 0; i < n; i++) {
		char *str;
		int A[10], DP = 1, IP=0;
		for(j = 0; j < 10; j++) A[j]=0;
		scanf("%d %d", &l, &r);
		str = (char*)malloc(r-l+2);
		memcpy(str, &(str1[l-1]), r-l+1);
        int len1 = r-l+1;
        str[len1] = 0;
		for(;IP >=0 && IP < len1;) {
		  //  printf("undo str=%s IP=%d(%c)\n", str, IP, str[IP]);
            if (str[IP] >= '0' && str[IP] <= '9') {
                A[(int)str[IP]-(int)'0']++;
                if(str[IP] != '0') (int)(str[IP])--; else str[IP] = del++;

            } else {
                if (str[IP] == '>') {
                    DP = 1;
                    if (IP < len1-1 && (str[IP+1] < '0' && str[IP+1] > '9')) str[IP] = del++;
                } else if (str[IP] == '<') {
                    DP = 0;
                    if (IP >0 && (str[IP-1] < '0' && str[IP-1] > '9')) str[IP] = del++;
                }
            }
            if(del) {
                del =0;
                for(k = 0, j = 0; j < len1; k++, j++) {
                    str[k] = str[j];
                    if(k-IP) k--;
                }
                str[k]=0;
                len1--;
            }
            if (DP) IP++; else IP--;
           // printf("redo str=%s IP=%d(%c)\n", str, IP, str[IP]);
		}

		for (j = 0; j < 10; j++) printf("%d ", A[j]);
		printf("\n");
	}
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main () {
	int len,l, r, n, i, j, k, del = 0;
	char *str1;
	scanf("%d %d", &len, &n);
	str1 = (char*)malloc(len);
	scanf("%s", str1);
	for (i = 0; i < n; i++) {
		char *str;
		int A[10], DP = 1, IP=0;
		for(j = 0; j < 10; j++) A[j]=0;
		scanf("%d %d", &l, &r);
		str = (char*)malloc(r-l+2);
		memcpy(str, &(str1[l-1]), r-l+1);
        int len1 = r-l+1;
        str[len1] = 0;
		for(;IP >=0 && IP < len1;) {
            if (str[IP] >= '0' && str[IP] <= '9') {
                A[(int)str[IP]-(int)'0']++;
                if(str[IP] != '0') (int)(str[IP])--; else str[IP] = del++;

            } else {
                if (str[IP] == '>') {
                    DP = 1;
                    if (IP < len1-1 && (str[IP+1] < '0' && str[IP+1] > '9')) str[IP] = del++;
                } else if (str[IP] == '<') {
                    DP = 0;
                    if (IP >0 && (str[IP-1] < '0' && str[IP-1] > '9')) str[IP] = del++;
                }
            }
            if(del) {
                del =0;
                str[IP] = 0;
                for(k = 0, j = 0; k < len1-1; k++, j++) {
                    if(!(k-IP)) {
                        j++;
                    }
                    str[k] = str[j];
                }
                len1--;
                str[len1] = 0;
                if (!DP) DP--;
            }else if (DP) IP++; else IP--;
		}

		for (j = 0; j < 10; j++) printf("%d ", A[j]);
		printf("\n");
	}
    return 0;
}


#include <cstdio>
#include <cstring>
int n,q,syc[15],yon,mark[105],l,r,last,bayrak;
char d[105],yed[105];
int main ()
{
    //freopen("oku.in","r",stdin);
    scanf("%d %d",&n,&q);
    for (int i = 1; i <= n; i++)
        scanf(" %c",&d[i]);
    d[0]='0';
    for (int i = 0; i < q; i++)
    {
        scanf("%d %d",&l,&r);
        yon=1;
        strcpy(yed,d);
        memset(mark,0,105);
        for (int j = l; j >=l && j<=r; j+=yon)
        {
            if(yed[j]>='0' && yed[j]<='9' && mark[j]==0)
            {
                syc[yed[j]-'0']++;
                if(yed[j]=='0')
                    mark[j]=1;
                last=j;
                yed[j]--;
            }
            else if(yed[j]=='>' && !mark[j])
            {
                if(yed[last]=='<' || yed[last]=='>')
                    mark[last]=1;
                last=j;
                yon=1;
            }
            else if(yed[j]=='<' && !mark[j])
            {
                if(yed[last]=='<' || yed[last]=='>')
                    mark[last]=1;
                last=j;
                yon=-1;
            }
        }
        for (int j = 0; j < 10; j++)
        {
            printf("%d ",syc[j]);
            syc[j]=0;
        }
        printf("\n");

    }

}


#include <cstdio>
#include <cstring>
int n,q,syc[15],yon,mark[105],l,r,last,bayrak;
char d[105],yed[105];
int main ()
{
    //freopen("oku.in","r",stdin);
    scanf("%d %d",&n,&q);
    for (int i = 1; i <= n; i++)
        scanf(" %c",&d[i]);

    for (int i = 0; i < q; i++)
    {
        scanf("%d %d",&l,&r);
        yon=1;last=0;
        for (int j = l; j <=r ; j++)
        {
            yed[j]=d[j];
            mark[j]=0;
        }

        for (int j = l; j >=l && j<=r; j+=yon)
        {
            if(yed[j]>='0' && yed[j]<='9' && mark[j]==0)
            {
                syc[yed[j]-'0']++;
                if(yed[j]=='0')
                    mark[j]=1;
                last=j;
                yed[j]--;
            }
            else if(yed[j]=='>' && !mark[j])
            {
                if(yed[last]=='<' || yed[last]=='>')
                    mark[last]=1;
                last=j;
                yon=1;
            }
            else if(yed[j]=='<' && !mark[j])
            {
                if(yed[last]=='<' || yed[last]=='>')
                    mark[last]=1;
                last=j;
                yon=-1;
            }
        }
        for (int j = 0; j < 10; j++)
        {
            printf("%d ",syc[j]);
            syc[j]=0;
        }
        printf("\n");
    }

}


#include <cstdio>
#include <cstring>
int n,q,syc[15],yon,mark[105],l,r,last,bayrak;
char d[105],yed[105];
int main ()
{
    //freopen("oku.in","r",stdin);
    scanf("%d %d",&n,&q);
    for (int i = 1; i <= n; i++)
        scanf(" %c",&d[i]);
    for (int i = 0; i < q; i++)
    {
        scanf("%d %d",&l,&r);
        yon=1;
        strcpy(yed,d);
        memset(mark,0,105);
        for (int j = l; j >=l && j<=r; j+=yon)
        {
            if(yed[j]>='0' && yed[j]<='9' && mark[j]==0)
            {
                syc[yed[j]-'0']++;
                if(yed[j]=='0')
                    mark[j]=1;
                last=j;
                yed[j]--;
            }
            else if(yed[j]=='>' && !mark[j])
            {
                if(yed[last]=='<' || yed[last]=='>')
                    mark[last]=1;
                last=j;
                yon=1;
            }
            else if(yed[j]=='<' && !mark[j])
            {
                if(yed[last]=='<' || yed[last]=='>')
                    mark[last]=1;
                last=j;
                yon=-1;
            }
        }
        for (int j = 0; j < 10; j++)
        {
            printf("%d ",syc[j]);
            syc[j]=0;
        }
        printf("\n");

    }

}


#include <iostream>
#include <vector>

using namespace std;

bool check(vector<char>& v)
{
    for(int i = 1; i < (int)v.size() - 1; i++)
    {
        if(v[i] != '-')
            return false;
    }
    return true;
}

void journey(vector<char>& v, int& p, int& d)
{
    if(v[p] == '>')
        d = 1;
    else if(v[p] == '<')
        d = -1;
    p += d;

    int k = p;
    while(v[k] == '-')
        k += d;
    if(v[k] == '<' || v[k] == '>')
    {
        v[p + d * -1] = '-';
        d = v[k] == '<' ? -1 : 1;
        //p = k;
        journey(v, k, d);
    }
    p = k;
}

int main()
{
    int n, q;
    cin >> n >> q;
    vector<char> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }

    for (int i = 0; i < q; i++)
    {

        vector<int> out(10, 0);
        int l, r, p = 1, d = 1;
        cin >> l >> r;
        vector<char> cmd(r - l + 1 + 2);
        cmd[0] = '*';
        cmd[r - l + 2] = '*';
        for(int j = 0; j < r - l + 1; j++)
        {
            cmd[j + 1] = v[l - 1 + j];
        }
        bool finished = true;
        while (cmd[p] != '*' && !check(cmd))
        {
            if (cmd[p] >= '0' && cmd[p] <= '9')
            {
                out[cmd[p] - '0']++;
                cmd[p]--;
                if (cmd[p] < '0')
                    cmd[p] = '-';
                p += d;
            }
            else if(cmd[p] == '-')
            {p += d;}
            else //if(cmd[p] == '>' || cmd[p] == '<')
            {
                journey(cmd, p, d);
            }
        }
        for (int j = 0; j < 10; j++)
        {
            cout << out[j] << ' ';
        }
        cout << endl;
    }

}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n, q;
	cin >> n >> q;
	vector<char> v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
	}

	for (int i = 0; i < q; i++)
	{

		vector<int> out(10, 0);
		int l, r, p = 1, d = 1;
		cin >> l >> r;
		vector<char> cmd(r - l + 1);
		for(int j = 0; j < r - l + 1; j++)
		{
			cmd[j] = v[l - 1 + j];
		}
		while (p >= 0 && p < (int)cmd.size())
		{
			if (cmd[p] >= '0' && cmd[p] <= '9')
			{
				out[cmd[p] - '0']++;
				cmd[p]--;
				if (cmd[p] < '0')
				{
					cmd.erase(cmd.begin() + p);
				}
			}
			else
			{
				int dif = 0;
				if(cmd[p] == '<' && d == 1)
				{
					d = -1;
					dif = -1;
				}
				if(cmd[p] == '>' && d == -1)
				{
					d = 1;
					dif = 1;
				}
				if (dif != 0)
				{
					cmd.erase(cmd.begin() + p);
				}
			}
			if(p == 0)
			{
				p--;
			}
			p += d;
		}
		for (int j = 0; j < 10; j++)
		{
			cout << out[j] << ' ';
		}
		cout << endl;
	}

}


#include <iostream>
#include <vector>

using namespace std;

bool check(vector<char>& v)
{
    for(int i = 1; i < (int)v.size() - 1; i++)
    {
        if(v[i] != '-')
            return false;
    }
    return true;
}

int main()
{
    int n, q;
    cin >> n >> q;
    vector<char> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }

    for (int i = 0; i < q; i++)
    {

        vector<int> out(10, 0);
        int l, r, p = 1, d = 1;
        cin >> l >> r;
        vector<char> cmd(r - l + 1 + 2);
        cmd[0] = '*';
        cmd[r - l + 2] = '*';
        for(int j = 0; j < r - l + 1; j++)
        {
            cmd[j + 1] = v[l - 1 + j];
        }
        while (cmd[p] != '*' && !check(cmd))
        {
            if (cmd[p] >= '0' && cmd[p] <= '9')
            {
                out[cmd[p] - '0']++;
                cmd[p]--;
                if (cmd[p] < '0')
                {
                    cmd[p] = '-';
                }
                p += d;
            }
            else if(cmd[p] == '-')
            {p += d;}
            else if(cmd[p] == '>' || cmd[p] == '<')
            {
                if(cmd[p] == '>')
                    d = 1;
                else if(cmd[p] == '<')
                    d = -1;

                p += d;

                int k = p;
                while(cmd[k] == '-')
                {
                    k += d;
                }
                if(cmd[k] == '<' || cmd[k] == '>')
                {
                    cmd[p + d * -1] = '-';
                    d = cmd[k] == '<' ? -1 : 1;
                }
            }

        }
        for (int j = 0; j < 10; j++)
        {
            cout << out[j] << ' ';
        }
        cout << endl;
    }

}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n, q;
	cin >> n >> q;
	vector<char> v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
	}

	for (int i = 0; i < q; i++)
	{

		vector<int> out(10, 0);
		int l, r, p = 1, d = 1;
		cin >> l >> r;
		vector<char> cmd(r - l + 1 + 2);
		cmd[0] = '*';
		cmd[r - l + 2] = '*';
		for(int j = 0; j < r - l + 1; j++)
		{
			cmd[j + 1] = v[l - 1 + j];
		}
		while (cmd[p] != '*')
		{
			if (cmd[p] >= '0' && cmd[p] <= '9')
			{
				out[cmd[p] - '0']++;
				cmd[p]--;
				if (cmd[p] < '0')
				{
					cmd[p] = '*';
				}
			}
			else
			{
				bool dif = false;
				if(cmd[p] == '<' && d == 1)
				{
					d = -1;
					dif = true;
				}
				if(cmd[p] == '>' && d == -1)
				{
					d = 1;
					dif = true;
				}
				if (dif)
				{
					cmd[p] = '*';
				}
			}
			p += d;
		}
		for (int j = 0; j < 10; j++)
		{
			cout << out[j] << ' ';
		}
		cout << endl;
	}

}


#include <iostream>
#include <vector>

using namespace std;

bool check(vector<char>& v)
{
	for(int i = 1; i < (int)v.size() - 1; i++)
	{
		if(v[i] != '-')
			return false;
	}
	return true;
}

int main()
{
	int n, q;
	cin >> n >> q;
	vector<char> v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
	}

	for (int i = 0; i < q; i++)
	{

		vector<int> out(10, 0);
		int l, r, p = 1, d = 1;
		cin >> l >> r;
		vector<char> cmd(r - l + 1 + 2);
		cmd[0] = '*';
		cmd[r - l + 2] = '*';
		for(int j = 0; j < r - l + 1; j++)
		{
			cmd[j + 1] = v[l - 1 + j];
		}
		while (cmd[p] != '*' && !check(cmd))
		{
			if (cmd[p] >= '0' && cmd[p] <= '9')
			{
				out[cmd[p] - '0']++;
				cmd[p]--;
				if (cmd[p] < '0')
				{
					cmd[p] = '-';
				}
			}
			else if(cmd[p] == '-')
			{}
			else
			{
				bool dif = false;
				if(cmd[p] == '<' && d == 1)
				{
					d = -1;
					dif = true;
				}
				if(cmd[p] == '>' && d == -1)
				{
					d = 1;
					dif = true;
				}
				if (dif)
				{
					cmd[p] = '-';
				}
			}
			p += d;
		}
		for (int j = 0; j < 10; j++)
		{
			cout << out[j] << ' ';
		}
		cout << endl;
	}

}


#include <iostream>
#include <vector>

using namespace std;

bool check(vector<char>& v)
{
    for(int i = 1; i < (int)v.size() - 1; i++)
    {
        if(v[i] != '-')
            return false;
    }
    return true;
}

int main()
{
    int n, q;
    cin >> n >> q;
    vector<char> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }

    for (int i = 0; i < q; i++)
    {

        vector<int> out(10, 0);
        int l, r, p = 1, d = 1;
        cin >> l >> r;
        vector<char> cmd(r - l + 1 + 2);
        cmd[0] = '*';
        cmd[r - l + 2] = '*';
        for(int j = 0; j < r - l + 1; j++)
        {
            cmd[j + 1] = v[l - 1 + j];
        }
        while (cmd[p] != '*' && !check(cmd))
        {
            if (cmd[p] >= '0' && cmd[p] <= '9')
            {
                out[cmd[p] - '0']++;
                cmd[p]--;
                if (cmd[p] < '0')
                {
                    cmd[p] = '-';
                }
            }
            else if(cmd[p] == '-')
            {}
            else if(cmd[p] == '>' || cmd[p] == '<')
            {
                bool dif = false;
                if(cmd[p] == '<' && d == 1)
                {
                    d = -1;
                    dif = true;
                }
                if(cmd[p] == '>' && d == -1)
                {
                    d = 1;
                    dif = true;
                }
                if (dif)
                {
                    int k = p + d;
                    while(cmd[k] == '-')
                    {
                        k += d;
                    }
                    if(cmd[k] == '<' || cmd[k] == '>')
                    {
                        cmd[p] = '-';
                        d *= -1;
                    }
                }
            }
            p += d;
        }
        for (int j = 0; j < 10; j++)
        {
            cout << out[j] << ' ';
        }
        cout << endl;
    }

}


#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <utility>
#include <functional>
#include <valarray>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <climits>

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REV(i, a, n) for(int i = a; i > n; i--)

template<typename T> T gcd(T a, T b) {
    if(!b) return a;
    return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

typedef long long ll;
typedef long double ld;

const int MAXN = 110;
int l, r, ans[15];
char S[MAXN], SS[MAXN];

void simulate(void) {
    memset(ans, 0, sizeof(ans));
    char base = '>', last = 'X';
    int start = l;
    strcpy(SS, S);
    while(1) {
        if(start < l || start > r) break;
        if(SS[start] != '<' && SS[start] != '>' && SS[start] != '$') {
            ans[SS[start]-'0'] += 1;
            if(SS[start] == 0) SS[start] = '$';
            else SS[start] -= 1;
        } else {
            base = SS[start];
        }
        if(base == '<') {
            start -= 1;
            while(start >= l && SS[start] == '$') {
                start -= 1;
            }
        } else {
            start += 1;
            while(start <= r && SS[start] == '$') {
                start += 1;
            }
        }
        if((SS[start] == '<' && last == '>') || (SS[start] == '>' && last == '<')) break;
        last = SS[start];
    }
    REP(i, 10) {
        printf("%d ", ans[i]);
    }
    puts("");
}

int main(void) {
    int N, Q;
    scanf("%d%d%s", &N, &Q, S);
    REP(i, Q) {
        scanf("%d%d", &l, &r);
        l--;
        r--;
        simulate();
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <utility>
#include <functional>
#include <valarray>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <climits>

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REV(i, a, n) for(int i = a; i > n; i--)

template<typename T> T gcd(T a, T b) {
    if(!b) return a;
    return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

typedef long long ll;
typedef long double ld;

const int MAXN = 110;
int l, r, ans[15];
char S[MAXN], SS[MAXN];

void simulate(void) {
    memset(ans, 0, sizeof(ans));
    char base = '>', last = 'X';
    int start = l;
    strcpy(SS, S);
    while(1) {
        if(start < l || start > r) break;
        if(SS[start] != '<' && SS[start] != '>' && SS[start] != '$') {
            ans[SS[start]-'0'] += 1;
            if(SS[start] == '0') SS[start] = '$';
            else SS[start] -= 1;
        } else {
            base = SS[start];
        }
        int help = start;
        if(base == '<') {
            start -= 1;
            while(start >= l && SS[start] == '$') {
                start -= 1;
            }
            if(SS[start] == '>' && SS[help] == '<') {
                SS[help] = '$';
            }
        } else {
            start += 1;
            while(start <= r && SS[start] == '$') {
                start += 1;
            }
            if(SS[start] == '<' && SS[help] == '>') {
                SS[help] = '$';
            }
        }
    }
    REP(i, 10) {
        printf("%d ", ans[i]);
    }
    puts("");
}

int main(void) {
    int N, Q;
    scanf("%d%d%s", &N, &Q, S);
    REP(i, Q) {
        scanf("%d%d", &l, &r);
        l--;
        r--;
        simulate();
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <utility>
#include <functional>
#include <valarray>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <climits>

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REV(i, a, n) for(int i = a; i > n; i--)

template<typename T> T gcd(T a, T b) {
    if(!b) return a;
    return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

typedef long long ll;
typedef long double ld;

const int MAXN = 110;
int N, l, r, ans[15];
char S[MAXN], SS[MAXN];

void simulate(void) {
    memset(ans, 0, sizeof(ans));
    char base = '>', last = 'X';
    int start = l;
    strcpy(SS, S);
    while(1) {
        if(start < l || start > r) break;
        if(SS[start] != '<' && SS[start] != '>' && SS[start] != '$') {
            ans[SS[start]-'0'] += 1;
            if(SS[start] == '0') SS[start] = '$';
            else SS[start] -= 1;
        } else {
            base = SS[start];
        }
        int help = start;
        if(base == '<') {
            start -= 1;
            while(start >= -1 && SS[start] == '$') {
                start -= 1;
            }
            if(SS[start] == '>' && (SS[help] == '<' || SS[help] == '>')) {
                SS[help] = '$';
            }
        } else {
            start += 1;
            while(start <= N && SS[start] == '$') {
                start += 1;
            }
            if(SS[start] == '<' && (SS[help] == '<' || SS[help] == '>')) {
                SS[help] = '$';
            }
        }
    }
    REP(i, 10) {
        printf("%d ", ans[i]);
    }
    puts("");
}

int main(void) {
    int Q;
    scanf("%d%d%s", &N, &Q, S);
    REP(i, Q) {
        scanf("%d%d", &l, &r);
        l--;
        r--;
        simulate();
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <utility>
#include <functional>
#include <valarray>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <climits>

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REV(i, a, n) for(int i = a; i > n; i--)

template<typename T> T gcd(T a, T b) {
    if(!b) return a;
    return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

typedef long long ll;
typedef long double ld;

const int MAXN = 110;
int N, l, r, ans[15];
char S[MAXN], SS[MAXN];

void simulate(void) {
    memset(ans, 0, sizeof(ans));
    char base = '>';
    int start = l;
    strcpy(SS, S);
    // $ means removed
    while(1) {
        if(start < l || start > r) break;
        if(SS[start] != '<' && SS[start] != '>' && SS[start] != '$') {
            ans[SS[start]-'0'] += 1;
            if(SS[start] == '0') SS[start] = '$';
            else SS[start] -= 1;
        } else {
            base = SS[start];
        }
        int help = start;
        if(base == '<') {
            start -= 1;
            while(start >= -1 && SS[start] == '$') {
                start -= 1;
            }
            if((SS[start] == '<' || SS[start] == '>') && (SS[help] == '<' || SS[help] == '>')) {
                SS[help] = '$';
            }
        } else {
            start += 1;
            while(start <= N && SS[start] == '$') {
                start += 1;
            }
            if((SS[start] == '<' || SS[start] == '>') && (SS[help] == '<' || SS[help] == '>')) {
                SS[help] = '$';
            }
        }
    }
    REP(i, 10) {
        printf("%d ", ans[i]);
    }
    puts("");
}

int main(void) {
    int Q;
    scanf("%d%d%s", &N, &Q, S);
    REP(i, Q) {
        scanf("%d%d", &l, &r);
        l--;
        r--;
        simulate();
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <utility>
#include <functional>
#include <valarray>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <climits>

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REV(i, a, n) for(int i = a; i > n; i--)

template<typename T> T gcd(T a, T b) {
    if(!b) return a;
    return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

typedef long long ll;
typedef long double ld;

const int MAXN = 110;
int N, l, r, ans[15];
char S[MAXN], SS[MAXN];

void simulate(void) {
    memset(ans, 0, sizeof(ans));
    char base = '>';
    int start = l;
    strcpy(SS, S);
    // $ means removed
    while(1) {
        if(start < l || start > r) break;
        puts(SS);
        if(SS[start] != '<' && SS[start] != '>' && SS[start] != '$') {
            ans[SS[start]-'0'] += 1;
            if(SS[start] == '0') SS[start] = '$';
            else SS[start] -= 1;
        } else {
            base = SS[start];
        }
        int help = start;
        if(base == '<') {
            start -= 1;
            while(start >= -1 && SS[start] == '$') {
                start -= 1;
            }
            if((SS[start] == '<' || SS[start] == '>') && (SS[help] == '<' || SS[help] == '>')) {
                SS[help] = '$';
            }
        } else {
            start += 1;
            while(start <= N && SS[start] == '$') {
                start += 1;
            }
            if((SS[start] == '<' || SS[start] == '>') && (SS[help] == '<' || SS[help] == '>')) {
                SS[help] = '$';
            }
        }
    }
    REP(i, 10) {
        printf("%d ", ans[i]);
    }
    puts("");
}

int main(void) {
    int Q;
    scanf("%d%d%s", &N, &Q, S);
    REP(i, Q) {
        scanf("%d%d", &l, &r);
        l--;
        r--;
        simulate();
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <utility>
#include <functional>
#include <valarray>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <climits>

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REV(i, a, n) for(int i = a; i > n; i--)

template<typename T> T gcd(T a, T b) {
    if(!b) return a;
    return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

typedef long long ll;
typedef long double ld;

const int MAXN = 110;
int l, r, ans[15];
char S[MAXN], SS[MAXN];

void simulate(void) {
    memset(ans, 0, sizeof(ans));
    char base = '>', last = 'X';
    int start = l;
    strcpy(SS, S);
    while(1) {
        if(start < l || start > r) break;
        if(SS[start] != '<' && SS[start] != '>' && SS[start] != '$') {
            ans[SS[start]-'0'] += 1;
            if(SS[start] == '0') SS[start] = '$';
            else SS[start] -= 1;
        } else {
            base = SS[start];
        }
        int help = start;
        if(base == '<') {
            start -= 1;
            while(start >= l && SS[start] == '$') {
                start -= 1;
            }
            if(SS[start] == '>' && (SS[help] == '<' || SS[help] == '>')) {
                SS[help] = '$';
            }
        } else {
            start += 1;
            while(start <= r && SS[start] == '$') {
                start += 1;
            }
            if(SS[start] == '<' && (SS[help] == '<' || SS[help] == '>')) {
                SS[help] = '$';
            }
        }
    }
    REP(i, 10) {
        printf("%d ", ans[i]);
    }
    puts("");
}

int main(void) {
    int N, Q;
    scanf("%d%d%s", &N, &Q, S);
    REP(i, Q) {
        scanf("%d%d", &l, &r);
        l--;
        r--;
        simulate();
    }
    return 0;
}


/*#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;
#define MAX 1000000
int y,k,n;
int D[MAX];
int main() {
    int i,j;
    scanf("%d%d%d",&y,&k,&n);
    D[1] = k;
    for(i = 2; i*k <= n; ++i) D[i] = i*k;

    bool ok=false;
    for(j = 1; j <= i; ++j)
      if(D[j]>y){
         printf("%d ", D[j]-y);
         ok=true;
     }

    if(!ok) printf("-1");

    return 0;
}*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;

#define MAX 105

int n, q;
char cad[MAX], aux[MAX];
int sol[10];

int main() {

    scanf("%d%d",&n,&q);
    scanf("%s", cad);

    for(int k = 0; k < q; ++k){
        int a, b;
        scanf("%d%d",&a,&b);
        a--; b--;
        for(int i = a; i <= b; ++i) aux[i-a] = cad[i];
        int inc = 1;
        int p = 0;
        bool ok = true;
        while (ok){
            if(aux[p]=='>') inc=1;
            else if(aux[p]=='<') inc=-1;
            else if(aux[p]>='0' && aux[p]<='9'){
                sol[aux[p]-'0']++;
                int n = aux[p]-'0';
                n--;
                if(n<0) aux[p]='$';
                else aux[p] = '0' + n;
            }
            int aux2=aux[p];
            p += inc;
            if(p>b) {
                ok=false;
                continue;
            }
            if(p<0){
                ok=false;
                continue;
            }
            if(aux2=='>'|| aux2=='<'){
                if(inc==-1){
                    int aux1=p; bool dime=false;
                    while(aux1>=0 && aux[aux1]!='>'){
                        if(aux[aux1]>='0' && aux[aux1]<='9') dime=true;
                        aux1--;
                    }
                    if(!dime){
                        ok=false;
                        continue;
                    }
                }else{
                    int aux1=p; bool dime=false;
                    while(aux1<=b-a && aux[aux1]!='<'){
                        if(aux[aux1]>='0' && aux[aux1]<='9') dime=true;
                        aux1++;
                    }
                    if(!dime){
                        ok=false;
                        continue;
                    }
                }
            }
        }
        for(int i = 0; i < 10; ++i)
         printf("%d ", sol[i]);
        printf("\n");
        fill(sol,sol+10,0);
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;

int n, q;
char cad[105];
char aux[105];
int sol[10];

int main() {

	scanf("%d%d",&n,&q);
	scanf("%s",cad);

	for(int i = 0; i < q; ++i){
		int a, b;
		scanf("%d%d",&a,&b);
		a--; b--;
		for(int j = a; j <= b; ++j) aux[j-a] = cad[j];
		int cp = 0, dp=1;
		bool ok=true;
		while(ok){
			if(aux[cp]=='>')dp=1;
			else if(aux[cp]=='<')dp=-1;
			else if(aux[cp]>='0' && aux[cp]<='9'){
				sol[aux[cp]-'0']++;
				if(aux[cp]-'0' == 0) aux[cp]='$';
				else aux[cp]--;
			}
			if(aux[cp]=='>' || aux[cp]=='<'){
			 bool dime=false;
			 for(int j = cp+1; j >= 0 && j<= (b-a); j+=dp){
			   if(aux[j]>='0' && aux[j]<='9') {
				   dime=true;
				   break;
			   }
			   if(aux[j]=='>' || aux[j]=='<') break;
			 }
			 if(!dime) aux[cp]='$';
			}
			cp+=dp;
			if(cp<0 || cp>(b-a)) ok=false;
		}
		for(int j = 0; j < 10; ++j)
			printf("%d ", sol[j]);
		printf("\n");
		fill(sol,sol+10,0);
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;

int n, q;
char cad[105];
char aux[105];
int sol[10];

int main() {

    scanf("%d%d",&n,&q);
    scanf("%s",cad);

    for(int i = 0; i < q; ++i){
        int a, b;
        scanf("%d%d",&a,&b);
        a--; b--;
        for(int j = a; j <= b; ++j) aux[j-a] = cad[j];
        int cp = 0, dp=1;
        bool ok=true;
        while(ok){
            if(aux[cp]=='>')dp=1;
            else if(aux[cp]=='<')dp=-1;
            else if(aux[cp]>='0' && aux[cp]<='9'){
                sol[aux[cp]-'0']++;
                if(aux[cp]-'0' == 0) aux[cp]='$';
                else aux[cp]--;
            }
            if(aux[cp]=='>' || aux[cp]=='<'){
             bool dime=false;
             for(int j = cp+dp; j >= 0 && j<= (b-a); j+=dp){
               if(aux[j]>='0' && aux[j]<='9') {
                   dime=true;
                   break;
               }
               if(aux[j]=='>' || aux[j]=='<') break;
             }
             if(!dime) aux[cp]='$';
            }
            cp+=dp;
            if(cp<0 || cp>(b-a)) ok=false;
        }
        for(int j = 0; j < 10; ++j)
            printf("%d ", sol[j]);
        printf("\n");
        fill(sol,sol+10,0);
    }

    return 0;
}


/*#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;
#define MAX 1000000
int y,k,n;
int D[MAX];
int main() {
	int i,j;
	scanf("%d%d%d",&y,&k,&n);
	D[1] = k;
	for(i = 2; i*k <= n; ++i) D[i] = i*k;

	bool ok=false;
	for(j = 1; j <= i; ++j)
	  if(D[j]>y){
		 printf("%d ", D[j]-y);
		 ok=true;
	 }

	if(!ok) printf("-1");

	return 0;
}*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;

#define MAX 105

int n, q;
char cad[MAX], aux[MAX];
int sol[10];

int main() {

	scanf("%d%d",&n,&q);
	scanf("%s", cad);

	for(int k = 0; k < q; ++k){
		int a, b;
		scanf("%d%d",&a,&b);
		a--; b--;
		for(int i = a; i <= b; ++i) aux[i-a] = cad[i];
		int inc = 1;
		int p = 0;
		bool ok = true;
		while (ok){
			if(aux[p]=='>') inc=1;
			else if(aux[p]=='<') inc=-1;
			else if(aux[p]>='0' && aux[p]<='9'){
				sol[aux[p]-'0']++;
				int n = aux[p]-'0';
				n--;
				if(n<0) aux[p]='$';
				else aux[p] = '0' + n;
			}
			int aux2=aux[p];
			p += inc;
			if(p>b) {
				ok=false;
				continue;
			}
			if(p<0){
				ok=false;
				continue;
			}
			if(aux2=='>'|| aux2=='<'){
				if(inc==-1){
					int aux1=p; bool dime=false;
					while(aux1>=0){
						if(aux[aux1]>='0' && aux[aux1]<='9') dime=true;
						aux1--;
					}
					if(!dime){
						ok=false;
						continue;
					}
				}else{
					int aux1=p; bool dime=false;
					while(aux1<=b){
						if(aux[aux1]>='0' && aux[aux1]<='9') dime=true;
						aux1++;
					}
					if(!dime){
						ok=false;
						continue;
					}
				}
			}
		}
		for(int i = 0; i < 10; ++i)
		 printf("%d ", sol[i]);
		printf("\n");
		fill(sol,sol+10,0);
	}

	return 0;
}


/*#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;
#define MAX 1000000
int y,k,n;
int D[MAX];
int main() {
    int i,j;
    scanf("%d%d%d",&y,&k,&n);
    D[1] = k;
    for(i = 2; i*k <= n; ++i) D[i] = i*k;

    bool ok=false;
    for(j = 1; j <= i; ++j)
      if(D[j]>y){
         printf("%d ", D[j]-y);
         ok=true;
     }

    if(!ok) printf("-1");

    return 0;
}*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;

#define MAX 105

int n, q;
char cad[MAX];
int sol[10];
vector<char> Q;
vector<char>::iterator p;

int main() {

    scanf("%d%d",&n,&q);
    scanf("%s", cad);
    int N=strlen(cad);

    for(int k = 0; k < q; ++k){
        int a, b;
        scanf("%d%d",&a,&b);
        a--; b--;
        Q.clear();
        for(int i = a; i <= b; ++i)
            Q.push_back(cad[i]);

        int inc=1;
        p = Q.begin();
        bool ok=true;
        while (ok){
            if(*p=='>') inc=1;
            else if(*p=='<') inc=-1;
            else{
                sol[*p-'0']++;
                int n = *p-'0';
                n--;
                if(n<0) Q.erase(p);
                else *p = '0' + n;
            }
            if(Q.empty()){
                ok=false;
                continue;
            }

            if(p==Q.begin() && inc==-1){
                ok=false;
                continue;
            }
            p += inc;
            if(p==Q.end()){
                ok=false;
                continue;
            }

            if(*(p+1)=='<' && inc==-1 && (*p=='<' || *p=='>') ) Q.erase(p+1);
            if(*(p-1)=='>' && inc==1 && (*p=='<' || *p=='>') ) Q.erase(p-1);
        }
        for(int i = 0; i < 10; ++i)
         printf("%d ", sol[i]);
        printf("\n");
        fill(sol,sol+10,0);
    }

    return 0;
}


/*#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;
#define MAX 1000000
int y,k,n;
int D[MAX];
int main() {
	int i,j;
	scanf("%d%d%d",&y,&k,&n);
	D[1] = k;
	for(i = 2; i*k <= n; ++i) D[i] = i*k;

	bool ok=false;
	for(j = 1; j <= i; ++j)
	  if(D[j]>y){
		 printf("%d ", D[j]-y);
		 ok=true;
	 }

	if(!ok) printf("-1");

	return 0;
}*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;

#define MAX 105

int n, q;
char cad[MAX], aux[MAX];
int sol[10];
vector<char> Q;

int main() {

	scanf("%d%d",&n,&q);
	scanf("%s", cad);
	int N=strlen(cad);

	for(int k = 0; k < q; ++k){
		int a, b;
		scanf("%d%d",&a,&b);
		a--; b--;
		for(int i = a; i <= b; ++i) aux[i-a] = cad[i];
		int inc = 1;
		int p = 0;
		bool ok = true;
		while (ok){
			if(aux[p]=='>') inc=1;
			else if(aux[p]=='<') inc=-1;
			else if(aux[p]>='0' && aux[p]<='9'){
				sol[aux[p]-'0']++;
				int n = aux[p]-'0';
				n--;
				if(n<0) aux[p]='$';
				else aux[p] = '0' + n;
			}else {
				ok=false;
				continue;
			}
			p += inc;

			if(inc==-1 && aux[p+1]=='<' && (aux[p]=='<' || aux[p]=='>') ){
				aux[p+1]='$';
			}
			if(inc==1 && aux[p-1]=='>' && (aux[p]=='<' || aux[p]=='>') ) {
				aux[p-1]='$';
			}
		}
		for(int i = 0; i < 10; ++i)
		 printf("%d ", sol[i]);
		printf("\n");
		fill(sol,sol+10,0);
	}

	return 0;
}


/*#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;
#define MAX 1000000
int y,k,n;
int D[MAX];
int main() {
	int i,j;
	scanf("%d%d%d",&y,&k,&n);
	D[1] = k;
	for(i = 2; i*k <= n; ++i) D[i] = i*k;

	bool ok=false;
	for(j = 1; j <= i; ++j)
	  if(D[j]>y){
		 printf("%d ", D[j]-y);
		 ok=true;
	 }

	if(!ok) printf("-1");

	return 0;
}*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;

#define MAX 105

int n, q;
char cad[MAX], aux[MAX];
int sol[10];
vector<char> Q;

int main() {

	scanf("%d%d",&n,&q);
	scanf("%s", cad);
	int N=strlen(cad);

	for(int k = 0; k < q; ++k){
		int a, b;
		scanf("%d%d",&a,&b);
		a--; b--;
		for(int i = a; i <= b; ++i) aux[i-a] = cad[i];
		int inc = 1;
		int p = 0;
		bool ok = true;
		while (ok){
			if(aux[p]=='>') inc=1;
			else if(aux[p]=='<') inc=-1;
			else if(aux[p]>='0' && aux[p]<='9'){
				sol[aux[p]-'0']++;
				int n = aux[p]-'0';
				n--;
				if(n<0) aux[p]='$';
				else aux[p] = '0' + n;
			}
			int aux2=aux[p];
			p += inc;
			if(p>b) {
				ok=false;
				continue;
			}
			if(p<0){
				ok=false;
				continue;
			}
			if(aux2=='>'|| aux2=='<'){
				if(inc==-1){
					int aux1=p;
					while(aux[aux1]=='$' && aux1>=0)aux1--;
					if(aux[aux1]=='>' || aux[aux1]=='<'){
						ok=false;
						continue;
					}
				}else{
					int aux1=p;
					while(aux[aux1]=='$' && aux1<=b)aux1++;
					if(aux[aux1]=='>' || aux[aux1]=='<'){
						ok=false;
						continue;
					}
				}
			}
		}
		for(int i = 0; i < 10; ++i)
		 printf("%d ", sol[i]);
		printf("\n");
		fill(sol,sol+10,0);
	}

	return 0;
}


/*#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;
#define MAX 1000000
int y,k,n;
int D[MAX];
int main() {
    int i,j;
    scanf("%d%d%d",&y,&k,&n);
    D[1] = k;
    for(i = 2; i*k <= n; ++i) D[i] = i*k;

    bool ok=false;
    for(j = 1; j <= i; ++j)
      if(D[j]>y){
         printf("%d ", D[j]-y);
         ok=true;
     }

    if(!ok) printf("-1");

    return 0;
}*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;

#define MAX 105

int n, q;
char cad[MAX], aux[MAX];
int sol[10];
vector<char> Q;

int main() {

    scanf("%d%d",&n,&q);
    scanf("%s", cad);
    int N=strlen(cad);

    for(int k = 0; k < q; ++k){
        int a, b;
        scanf("%d%d",&a,&b);
        a--; b--;
        for(int i = a; i <= b; ++i) aux[i-a] = cad[i];
        int inc = 1;
        int p = 0;
        bool ok = true;
        while (ok){
            if(aux[p]=='>') inc=1;
            else if(aux[p]=='<') inc=-1;
            else if(aux[p]>='0' && aux[p]<='9'){
                sol[aux[p]-'0']++;
                int n = aux[p]-'0';
                n--;
                if(n<0) aux[p]='$';
                else aux[p] = '0' + n;
            }
            int aux2=aux[p];
            p += inc;
            if(p>b) {
                ok=false;
                continue;
            }
            if(p<0){
                ok=false;
                continue;
            }
            if(aux2=='>'|| aux2=='<'){
                if(inc==-1){
                    int aux1=p;
                    while(aux[aux1]=='$' && aux1>=0)aux1--;
                    if(aux[aux1]=='>' || aux[aux1]=='<'){
                        ok=false;
                        continue;
                    }
                }else{
                    int aux1=p;
                    while(aux[aux1]=='$' && aux1<=b)aux1--;
                    if(aux[aux1]=='>' || aux[aux1]=='<'){
                        ok=false;
                        continue;
                    }
                }
            }
        }
        for(int i = 0; i < 10; ++i)
         printf("%d ", sol[i]);
        printf("\n");
        fill(sol,sol+10,0);
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;

int n, q;
char cad[105];
char aux[105];
int sol[10];

int main() {

    scanf("%d%d",&n,&q);
    scanf("%s",cad);

    for(int i = 0; i < q; ++i){
        int a, b;
        scanf("%d%d",&a,&b);
        a--; b--;
        for(int j = a; j <= b; ++j) aux[j-a] = cad[j];
        int cp = 0, dp=1;
        bool ok=true;
        while(ok){
            if(aux[cp]=='>')dp=1;
            else if(aux[cp]=='<')dp=-1;
            else{
                sol[aux[cp]-'0']++;
                if(aux[cp]-'0' == 0) aux[cp]='$';
                else aux[cp]--;
            }
            if(aux[cp]=='>' || aux[cp]=='<'){
             bool dime=false;
             for(int j = cp; j >= 0 && j<= (b-a); j+=dp){
               if(aux[cp]=='>' && aux[j]=='<') break;
               if(aux[cp]=='<' && aux[j]=='>') break;
               if(aux[j]>='0' && aux[j]<='9') dime=true;
             }
             if(!dime) aux[cp]='$';
            }
            cp+=dp;
            if(cp<0 || cp>(b-a)) ok=false;
        }
        for(int j = 0; j < 10; ++j)
            printf("%d ", sol[j]);
        printf("\n");
        fill(sol,sol+10,0);
    }

    return 0;
}


/*#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;
#define MAX 1000000
int y,k,n;
int D[MAX];
int main() {
    int i,j;
    scanf("%d%d%d",&y,&k,&n);
    D[1] = k;
    for(i = 2; i*k <= n; ++i) D[i] = i*k;

    bool ok=false;
    for(j = 1; j <= i; ++j)
      if(D[j]>y){
         printf("%d ", D[j]-y);
         ok=true;
     }

    if(!ok) printf("-1");

    return 0;
}*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;

#define MAX 105

int n, q;
char cad[MAX], aux[MAX];
int sol[10];

int main() {

    scanf("%d%d",&n,&q);
    scanf("%s", cad);

    for(int k = 0; k < q; ++k){
        int a, b;
        scanf("%d%d",&a,&b);
        a--; b--;
        for(int i = a; i <= b; ++i) aux[i-a] = cad[i];
        int inc = 1;
        int p = 0;
        bool ok = true;
        while (ok){
            if(aux[p]=='>') inc=1;
            else if(aux[p]=='<') inc=-1;
            else if(aux[p]>='0' && aux[p]<='9'){
                sol[aux[p]-'0']++;
                int n = aux[p]-'0';
                n--;
                if(n<0) aux[p]='$';
                else aux[p] = '0' + n;
            }
            int aux2=aux[p];
            p += inc;
            if(p>b) {
                ok=false;
                continue;
            }
            if(p<0){
                ok=false;
                continue;
            }
            if(aux2=='>'|| aux2=='<'){
                if(inc==-1){
                    int aux1=p; bool dime=false;
                    while(aux1>=0){
                        if(aux[aux1]>='0' && aux[aux1]<='9') dime=true;
                        aux1--;
                    }
                    if(!dime){
                        ok=false;
                        continue;
                    }
                }else{
                    int aux1=p; bool dime=false;
                    while(aux1<=b-a){
                        if(aux[aux1]>='0' && aux[aux1]<='9') dime=true;
                        aux1++;
                    }
                    if(!dime){
                        ok=false;
                        continue;
                    }
                }
            }
        }
        for(int i = 0; i < 10; ++i)
         printf("%d ", sol[i]);
        printf("\n");
        fill(sol,sol+10,0);
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
using namespace std;

int n, q;
char cad[105];
char aux[105];
int sol[10];

int main() {

    scanf("%d%d",&n,&q);
    scanf("%s",cad);

    for(int i = 0; i < q; ++i){
        int a, b;
        scanf("%d%d",&a,&b);
        a--; b--;
        for(int j = a; j <= b; ++j) aux[j-a] = cad[j];
        int cp = 0, dp=1;
        bool ok=true;
        while(ok){
            if(aux[cp]=='>')dp=1;
            else if(aux[cp]=='<')dp=-1;
            else if(aux[cp]>='0' && aux[cp]<='9'){
                sol[aux[cp]-'0']++;
                if(aux[cp]-'0' == 0) aux[cp]='$';
                else aux[cp]--;
            }
            if(aux[cp]=='>' || aux[cp]=='<'){
             bool dime=false;
             for(int j = cp; j >= 0 && j<= (b-a); j+=dp){
               if(aux[cp]=='>' && aux[j]=='<') break;
               if(aux[cp]=='<' && aux[j]=='>') break;
               if(aux[j]>='0' && aux[j]<='9') dime=true;
             }
             if(!dime) aux[cp]='$';
            }
            cp+=dp;
            if(cp<0 || cp>(b-a)) ok=false;
        }
        for(int j = 0; j < 10; ++j)
            printf("%d ", sol[j]);
        printf("\n");
        fill(sol,sol+10,0);
    }

    return 0;
}


#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <cctype>
using namespace std;
//
int dig[10];
string str, sub;

bool isdigit(char c) {
     return c>='0' && c<='9';
}

string part(int ini, int fim, string st) {
       int i;
       string s="";
       for (i=ini; i<=fim; i++)
           s=s+st[i];
       return s;
}

bool val(int x) {
     return x>=0 && x<sub.size();
}

void debug(int x, int y) {
     printf ("cp=%d dp=%d\n", x, y);
     cout<<sub<<endl;
}

void calc() {
     int cp=0, dp=1;
     while (val(cp)) {
           if (isdigit(sub[cp])) {
              dig[sub[cp]-'0']++;
              if (sub[cp]=='0') {
                 sub=part(0, cp-1, sub)+part (cp+1, sub.size()-1,sub);
                 //cout<<sub<<endl;
                 if (dp<0)
                    cp--;
              }
              else {
                   sub[cp]--;
                   cp+=dp;
              }
           }
           else {
                if (sub[cp]=='<') {
                   dp=-1, cp--;
                   if (val(cp) && !isdigit(sub[cp]))
                      sub=part(0, cp,sub)+part(cp+2, sub.size()-1,sub);
                }
                else {
                     dp=1, cp++;
                     if (val(cp) && !isdigit(sub[cp]))
                        sub=part(0, cp-2, sub)+part(cp, sub.size()-1, sub);
                }
           }
           //debug(cp, dp);
     }
}

void print() {
     int i;
     for (i=0; i<10; i++)
         printf ("%d ", dig[i]);
     printf ("\n");
}

main () {
     int s, n, l, r;
     cin>>s>>n>>str;
     while (n--) {
           memset(dig, 0, sizeof(dig));
           cin>>l>>r;
           sub=part(l-1, r-1, str);
           calc();
           print();
     }
     return 0;
}


/*
ID: arysson2
PROG: file
LANG: C++
*/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <fstream>

#define lb lower_bound
#define pb push_back
#define pf push_front
#define mp make_pair
#define REP(i, a, b)     for (int i = int(a); i <= int(b); i++)

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<string, int> si;
typedef pair<int, int> ii;
typedef pair<char, int> ci;
typedef queue<si> qsi;
typedef queue<ii> qii;
typedef queue<ci> qci;
typedef queue<int> qi;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<ll, ll> mllll;
typedef map<char, int> mci;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<si> vsi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef list<char> lc;
typedef deque<int> di;

const int inf=1000000000;
const ll linf=1000000000000000000LL;

//ofstream fout ("file.out");
//ifstream fin ("file.in");
#define fin cin
#define fout cout

string str, sub;
int array[10];

int main() {
    int n, q, cp, dp, l, r;
    cin>>n>>q>>str;
    while (q--) {
          cin>>l>>r;
          memset(array, 0, sizeof(array));
          sub=str.substr(l-1, r-l+1);
          for (cp=0, dp=1; cp>=0 && cp<sub.size(); ) {
              if (isdigit(sub[cp])) {
                 array[sub[cp]-'0']++;
                 if (sub[cp]=='0') {
                    sub=sub.substr(0, cp-1)+sub.substr(cp+1, sub.size()-cp);
                    cp=dp==1?cp:cp-1;
                 }
                 else sub[cp]--, cp+=dp;
              }
              else {
                   dp=sub[cp]=='<'?-1:1;
                   if (cp+dp>=0 && cp+dp<sub.size() && !isdigit(sub[cp+dp])) {
                      sub=sub.substr(0, cp-1)+sub.substr(cp+1, sub.size()-cp);
                      cp=dp==1?cp:cp-1;
                   }
                   cp+=dp;
                   //cout<<sub<<endl;
              }
          }
          REP (i, 0, 9) printf ("%d ", array[i]);
          printf ("\n");
    }
    //system ("pause");
    return 0;
}


/*
ID: arysson2
PROG: file
LANG: C++
*/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <fstream>

#define lb lower_bound
#define pb push_back
#define pf push_front
#define mp make_pair
#define REP(i, a, b)     for (int i = int(a); i <= int(b); i++)

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<string, int> si;
typedef pair<int, int> ii;
typedef pair<char, int> ci;
typedef queue<si> qsi;
typedef queue<ii> qii;
typedef queue<ci> qci;
typedef queue<int> qi;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<ll, ll> mllll;
typedef map<char, int> mci;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<si> vsi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef list<char> lc;
typedef deque<int> di;

const int inf=1000000000;
const ll linf=1000000000000000000LL;

//ofstream fout ("file.out");
//ifstream fin ("file.in");
#define fin cin
#define fout cout

string str, sub;
int array[10];

int main() {
    int n, q, cp, dp, l, r;
    cin>>n>>q>>str;
    while (q--) {
          cin>>l>>r;
          memset(array, 0, sizeof(array));
          sub=str.substr(l-1, r-l+1);
          for (cp=0, dp=1; cp>=0 && cp<sub.size(); ) {
              if (isdigit(sub[cp])) {
                 array[sub[cp]-'0']++;
                 if (sub[cp]=='0') {
                    sub=sub.substr(0, cp-1)+sub.substr(cp+1, sub.size()-cp);
                    cp=dp==1?cp:cp-1;
                 }
                 else sub[cp]--, cp+=dp;
              }
              else {
                   dp=sub[cp]=='<'?-1:1;
                   if (cp+dp>=0 && cp+dp<sub.size() && !isdigit(sub[cp+dp])) {
                      sub=sub.substr(0, cp-1)+sub.substr(cp+1, sub.size()-cp);
                      cp=dp==1?cp:cp-1;
                   }
                   else cp+=dp;
              }
          }
          REP (i, 0, 9) printf ("%d ", array[i]);
          printf ("\n");
    }
    //system ("pause");
    return 0;
}


#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <cctype>
using namespace std;

int dig[10];
string str, sub;

bool isdigit(char c) {
     return c>='0' && c<='9';
}

string part(int ini, int fim, string st) {
       int i;
       string s="";
       for (i=ini; i<=fim; i++)
           s=s+st[i];
       return s;
}

bool val(int x) {
     return x>=0 && x<sub.size();
}

void debug(int x, int y) {
     printf ("cp=%d dp=%d\n", x, y);
     cout<<sub<<endl;
}

void calc() {
     int cp=0, dp=1;
     while (val(cp)) {
           if (isdigit(sub[cp])) {
              dig[sub[cp]-'0']++;
              if (sub[cp]=='0') {
                 sub=part(0, cp-1, sub)+part (cp+1, sub.size()-1,sub);
                 //cout<<sub<<endl;
                 if (dp<0)
                    cp--;
              }
              else {
                   sub[cp]--;
                   cp+=dp;
              }
           }
           else {
                if (sub[cp]=='<') {
                   dp=-1, cp--;
                   if (val(cp) && !isdigit(sub[cp]))
                      sub=part(0, cp,sub)+part(cp+2, sub.size()-1,sub);
                }
                else {
                     dp=1, cp++;
                     if (val(cp) && !isdigit(sub[cp]))
                        sub=part(0, cp-2, sub)+part(cp, sub.size()-1, sub);
                }
           }
           //debug(cp, dp);
     }
}

void print() {
     int i;
     for (i=0; i<10; i++)
         printf ("%d ", dig[i]);
     printf ("\n");
}

main () {
     int s, n, l, r;
     cin>>s>>n>>str;
     while (n--) {
           memset(dig, 0, sizeof(dig));
           cin>>l>>r;
           sub=part(l-1, r-1, str);
           calc();
           print();
     }
     return 0;
}


/*
ID: arysson2
PROG: file
LANG: C++
*/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <fstream>

#define lb lower_bound
#define pb push_back
#define pf push_front
#define mp make_pair
#define REP(i, a, b)     for (int i = int(a); i <= int(b); i++)

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<string, int> si;
typedef pair<int, int> ii;
typedef pair<char, int> ci;
typedef queue<si> qsi;
typedef queue<ii> qii;
typedef queue<ci> qci;
typedef queue<int> qi;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<ll, ll> mllll;
typedef map<char, int> mci;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<si> vsi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef list<char> lc;
typedef deque<int> di;

const int inf=1000000000;
const ll linf=1000000000000000000LL;

//ofstream fout ("file.out");
//ifstream fin ("file.in");
#define fin cin
#define fout cout

string str, sub;
int array[10];

int main() {
    int n, q, cp, dp, l, r;
    cin>>n>>q>>str;
    while (q--) {
          cin>>l>>r;
          memset(array, 0, sizeof(array));
          sub=str.substr(l-1, r-l+1);
          for (cp=0, dp=1; cp>=0 && cp<sub.size(); ) {
              if (isdigit(sub[cp])) {
                 array[sub[cp]-'0']++;
                 if (sub[cp]=='0') {
                    sub=sub.substr(0, cp-1)+sub.substr(cp+1, sub.size()-cp);
                    cp=dp==1?cp:cp-1;
                 }
                 else sub[cp]--, cp+=dp;
              }
              else {
                   dp=sub[cp]=='<'?-1:1;
                   if (cp+dp>=0 && cp+dp<sub.size() && !isdigit(sub[cp+dp])) {
                      sub=sub.substr(0, cp-1)+sub.substr(cp+1, sub.size()-cp);
                      cp=dp==1?cp:cp-1;
                   }
                   else cp+=dp;
              }
          }
          REP (i, 0, 9) printf ("%d ", array[i]);
          printf ("\n");
    }
    system ("pause");
    return 0;
}


/*
ID: arysson2
PROG: file
LANG: C++
*/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <fstream>

#define lb lower_bound
#define pb push_back
#define pf push_front
#define mp make_pair
#define REP(i, a, b)     for (int i = int(a); i <= int(b); i++)

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<string, int> si;
typedef pair<int, int> ii;
typedef pair<char, int> ci;
typedef queue<si> qsi;
typedef queue<ii> qii;
typedef queue<ci> qci;
typedef queue<int> qi;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<ll, ll> mllll;
typedef map<char, int> mci;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<si> vsi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef list<char> lc;
typedef deque<int> di;

const int inf=1000000000;
const ll linf=1000000000000000000LL;

//ofstream fout ("file.out");
//ifstream fin ("file.in");
#define fin cin
#define fout cout

string str, sub;
int array[10];

int main() {
    int n, q, cp, dp, l, r;
    cin>>n>>q>>str;
    while (q--) {
          cin>>l>>r;
          memset(array, 0, sizeof(array));
          sub=str.substr(l-1, r-l+1);
          for (cp=0, dp=1; cp>=0 && cp<sub.size(); ) {
              if (isdigit(sub[cp])) {
                 array[sub[cp]-'0']++;
                 if (sub[cp]=='0') {
                    sub.erase(cp, 1);
                    cp=dp==1?cp:cp-1;
                 }
                 else sub[cp]--, cp+=dp;
              }
              else {
                   dp=sub[cp]=='<'?-1:1;
                   if (cp+dp>=0 && cp+dp<sub.size() && !isdigit(sub[cp+dp])) {
                      sub.erase(cp, 1);
                      cp=dp==1?cp:cp-1;
                   }
                   else cp+=dp;
                   //cout<<sub<<endl;
              }
          }
          REP (i, 0, 9) printf ("%d ", array[i]);
          printf ("\n");
    }//
    //system ("pause");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
using namespace std;
int n,q,ans[10];
const int LEFT=-1,RIGHT=1;
char order[105];
void work(int left,int right){
    bool moved[105];
    memset(moved,false,sizeof(moved));
    char temp[105]; int tt=1;
    char prev=0;
    memset(temp,0,sizeof(temp));
    for(int i=left;i<=right;i++) temp[tt++]=order[i];
    int CP=1,DP=RIGHT;
    while(CP>=1&&CP<=(right-left+1)){
        if(moved[CP]){
           CP+=DP;
           continue;
        }
        if((temp[CP]=='>'||temp[CP]=='<')&&(prev=='>'||prev=='<')){
           moved[CP-1]=true;
           CP+=DP;
           continue;
        }
        if(temp[CP]=='>') {DP=RIGHT;prev=temp[CP];}
        else if(temp[CP]=='<') {DP=LEFT;prev=temp[CP];}
        else if(temp[CP]>='0'&&temp[CP]<='9'){//if it is number
           ans[temp[CP]-'0']++;
           temp[CP]--;
           prev=temp[CP];
        }
        CP+=DP;
    }
}
int main()
{
    scanf("%d %d",&n,&q);
    cin>>order+1;
    for(int i=0;i<q;i++){
       int left,right;
       scanf("%d %d",&left,&right);
       memset(ans,0,sizeof(ans));
       work(left,right);
       for(int i=0;i<10;i++)
        printf("%d ",ans[i]);
       printf("\n");
    }
   // system("pause");
    return 0;
}


/*#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
using namespace std;
int n,q,ans[10];
const int LEFT=-1,RIGHT=1;
char order[105];
void work(int left,int right){
    bool moved[105];
    memset(moved,false,sizeof(moved));
    char temp[105]; int tt=1;
    int prev=1;
    memset(temp,0,sizeof(temp));
    for(int i=left;i<=right;i++) temp[tt++]=order[i];
    int CP=1,DP=RIGHT;
    while(CP>=1&&CP<=(right-left+1)){
        if(moved[CP]){
           CP+=DP;
           continue;
        }
        if((temp[CP]=='>'||temp[CP]=='<')&&(temp[prev]=='>'||temp[prev]=='<')){
           moved[prev]=true;
           CP+=DP;
           continue;
        }
        if(temp[CP]=='>') {DP=RIGHT;prev=CP;}
        else if(temp[CP]=='<') {DP=LEFT;prev=CP;}
        else if(temp[CP]>='0'&&temp[CP]<='9'){//if it is number
           ans[temp[CP]-'0']++;
           temp[CP]--;
           if(temp[CP]!=('0'-1)) prev=CP;

        }
        CP+=DP;
    }
}
int main()
{
    scanf("%d %d",&n,&q);
    cin>>order+1;
    for(int i=0;i<q;i++){
       int left,right;
       scanf("%d %d",&left,&right);
       memset(ans,0,sizeof(ans));
       work(left,right);
       for(int i=0;i<10;i++)
        printf("%d ",ans[i]);
       printf("\n");
    }
    system("pause");
    return 0;
}
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#define  N 105
using namespace std ;

int num[N] ;
char str[N] , st[N] ;

int main()
{
    int n , q , pos , flag , dir , l , r , i ;

    while ( scanf ( "%d%d%s" , &n , &q , str ) != EOF )
    {
        while ( q-- )
        {
            memset( num , 0 , sizeof ( num )) ;
            memcpy( st ,str , sizeof ( str )) ;
            scanf ( "%d%d" , &l , &r ) ;
            l-- ; r-- ;
            flag = 0 ; pos = 0 ; dir = 1 ;
            for( i = l ; i >= l && i <= r ; i += dir )
            {
                if ( st[i] >= '0' && st[i] <= '9' )
                {
                    num[st[i]-'0']++ ;
                    if ( st[i] == '0' ) st[i] = 0 ;
                    else
                    st[i]-- ;
                    flag = 0 ;// dir = 1 ;
                }
                else if ( st[i] == '>' )
                {
                    dir = 1 ;
                    if ( flag )
                    st[pos] = 0 ;
                    flag = 1 ; pos = i ;
                }
                else if ( st[i] == '<' )
                {
                    dir = -1 ;
                    if ( flag )
                    st[pos] = 0 ;
                    flag = 1 ; pos = i ;
                }
            }
            for ( i = 0 ; i <= 9 ; i++ )
            {
                if ( i )
                printf ( " %d" , num[i] ) ;
                else
                printf ( "%d" , num[i] ) ;
            }
            printf ( "\n" ) ;
        }
    }
    return 0 ;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
using namespace std;
int n,q,ans[10];
const int LEFT=-1,RIGHT=1;
char order[105];
void work(int left,int right){
    char temp[105]; int tt=1;
    int prev=1,isoper=false;
    memset(temp,0,sizeof(temp));
    for(int i=left;i<=right;i++) temp[tt++]=order[i];
    int CP=1,DP=RIGHT;
    while(CP>=1&&CP<=(right-left+1)){
        if(temp[CP]=='>') {
         if(isoper) temp[prev]=0;
         DP=RIGHT;
         prev=CP;
         isoper=true;
        }
        else if(temp[CP]=='<') {
          if(isoper)
            temp[prev]=0;
          DP=LEFT;
          prev=CP;
          isoper=true;
        }
        else if(temp[CP]>='0'&&temp[CP]<='9'){//if it is number
           ans[temp[CP]-'0']++;
           if(temp[CP]=='0') temp[CP]=0;
           temp[CP]--;
           isoper=false;
        }
        CP+=DP;
    }
}
int main()
{
    scanf("%d %d",&n,&q);
    cin>>order+1;
    for(int i=0;i<q;i++){
       int left,right;
       scanf("%d %d",&left,&right);
       memset(ans,0,sizeof(ans));
       work(left,right);
       for(int i=0;i<10;i++)
        printf("%d ",ans[i]);
       printf("\n");
    }
    system("pause");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
using namespace std;
int n,q,ans[10];
const int LEFT=-1,RIGHT=1;
char order[105];
void work(int left,int right){
    bool moved[105];
    memset(moved,false,sizeof(moved));
    char temp[105]; int tt=1;
    char prev=0;
    memset(temp,0,sizeof(temp));
    for(int i=left;i<=right;i++) temp[tt++]=order[i];
    int CP=1,DP=RIGHT;
    while(CP>=1&&CP<=(right-left+1)){
        if(moved[CP]){
           CP+=DP;
           continue;
        }
        if((temp[CP]=='>'||temp[CP]=='<')&&(prev=='>'||prev=='<')){
           moved[CP-DP]=true;
           CP+=DP;
           continue;
        }
        if(temp[CP]=='>') {DP=RIGHT;prev=temp[CP];}
        else if(temp[CP]=='<') {DP=LEFT;prev=temp[CP];}
        else if(temp[CP]>='0'&&temp[CP]<='9'){//if it is number
           ans[temp[CP]-'0']++;
           temp[CP]--;
           if(temp[CP]!=('0'-1)) prev=temp[CP];
        }
        CP+=DP;
    }
}
int main()
{
    scanf("%d %d",&n,&q);
    cin>>order+1;
    for(int i=0;i<q;i++){
       int left,right;
       scanf("%d %d",&left,&right);
       memset(ans,0,sizeof(ans));
       work(left,right);
       for(int i=0;i<10;i++)
        printf("%d ",ans[i]);
       printf("\n");
    }
    //system("pause");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
using namespace std;
int n,q,ans[10];
const int LEFT=-1,RIGHT=1;
char order[105];
void work(int left,int right){
    char temp[105]; int tt=1;
    int prev=1,isoper=false;
    memset(temp,0,sizeof(temp));
    for(int i=left;i<=right;i++) temp[tt++]=order[i];
    int CP=1,DP=RIGHT;
    while(CP>=1&&CP<=(right-left+1)){
        if(temp[CP]=='>') {
         if(isoper) temp[prev]=0;
         DP=RIGHT;
         prev=CP;
         isoper=true;
        }
        else if(temp[CP]=='<') {
          if(isoper)
            temp[prev]=0;
          DP=LEFT;
          prev=CP;
          isoper=true;
        }
        else if(temp[CP]>='0'&&temp[CP]<='9'){//if it is number
           ans[temp[CP]-'0']++;
           if(temp[CP]=='0') temp[CP]=0;
           temp[CP]--;
           isoper=false;
        }
        CP+=DP;
    }
}
int main()
{
    scanf("%d %d",&n,&q);
    cin>>order+1;
    for(int i=0;i<q;i++){
       int left,right;
       scanf("%d %d",&left,&right);
       memset(ans,0,sizeof(ans));
       work(left,right);
       for(int i=0;i<10;i++)
        printf("%d ",ans[i]);
       printf("\n");
    }
   // system("pause");
    return 0;
}


View Code

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#define  N 105
using namespace std ;

int num[N] ;
char str[N] , st[N] ;

int main()
{
    int n , q , pos , flag , dir , l , r , i ;

    while ( scanf ( "%d%d%s" , &n , &q , str ) != EOF )
    {
        while ( q-- )
        {
            memset( num , 0 , sizeof ( num )) ;
            memcpy( st ,str , sizeof ( str )) ;
            scanf ( "%d%d" , &l , &r ) ;
            l-- ; r-- ;
            flag = 0 ; pos = 0 ; dir = 1 ;
            for( i = l ; i >= l && i <= r ; i += dir )
            {
                if ( st[i] >= '0' && st[i] <= '9' )
                {
                    num[st[i]-'0']++ ;
                    if ( st[i] == '0' ) st[i] = 0 ;
                    else
                    st[i]-- ;
                    flag = 0 ;// dir = 1 ;
                }
                else if ( st[i] == '>' )
                {
                    dir = 1 ;
                    if ( flag )
                    st[pos] = 0 ;
                    flag = 1 ; pos = i ;
                }
                else if ( st[i] == '<' )
                {
                    dir = -1 ;
                    if ( flag )
                    st[pos] = 0 ;
                    flag = 1 ; pos = i ;
                }
            }
            for ( i = 0 ; i <= 9 ; i++ )
            {
                if ( i )
                printf ( " %d" , num[i] ) ;
                else
                printf ( "%d" , num[i] ) ;
            }
            printf ( "\n" ) ;
        }
    }
    return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<cstring>

using namespace std;

int n,q,l,r,f;
char s[500];char s2[500];
int c[10];
void L(int k);
bool end(int a){
	for(;a<r;a++){
		if(s[a]-'0'>=0&&s[a]-'0'<10){
			return true;
		}
		else if(s[a]=='<')return false;
	}
	return true;
}

void R(int j){
	for(;j>=l-1&&j<r;j++){

		//if(end(j)){
			if(s[j]=='>'){
				if(!end(j)){
				f=1;break;
				}
				else
				continue;
			}
			else if(s[j]=='c'){
				continue;
			}
			else if(s[j]=='<'){
				L(j);
			}
			else{
				c[s[j]-'0']++;
				if(s[j]=='0')s[j]='c';
				else
				s[j]--;
			}
		//}
	}
}
void L(int k){
	for(;k>=l-1&&k<r;k--){
		//if(end(k)){
			if(s[k]=='>'){
				R(k);
				if(f)break;
			}

			else if(s[k]=='<'||s[k]=='c'){

				continue;
			}
			else{
				c[s[k]-'0']++;
				if(s[k]=='0')s[k]='c';
				else
				s[k]=s[k]--;
			}
		//}
	}
}
int main(){
	scanf("%d%d",&n,&q);
	scanf("%s",s);

	memcpy(s2, s, sizeof(s2));
	for(int i=0;i<q;i++){
		scanf("%d%d",&l,&r);
		memcpy(s,s2,sizeof(s));
			f=0;
		memset(c,0,sizeof(c));
		R(l-1);
		for(int i=0;i<9;i++){
			printf("%d ",c[i]);
		}
		printf("%d\n",c[9]);
	}
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<cstring>

using namespace std;

int n,q,l,r,f;
char s[100];char s2[100];
int c[10];
void L(int k);
bool end(int a){
	for(;a<r;a++){
		if(s[a]-'0'>=0&&s[a]-'0'<10){
			return true;
		}
		else if(s[a]=='<')return false;
	}
	//return false;
}

void R(int j){
	for(;j>=l-1&&j<r;j++){

		//if(end(j)){
			if(s[j]=='>'){
				if(!end(j)){
				f=1;break;
				}
				else
				continue;
			}
			else if(s[j]-'0'<0&&s[j] != '<'){
				continue;
			}
			else if(s[j]=='<'){
				L(j);
			}
			else{
				c[s[j]-'0']++;
				s[j]=s[j]--;
			}
		//}
	}
}
void L(int k){
	for(;k>=l-1&&k<r;k--){
		//if(end(k)){
			if(s[k]=='>'){
				R(k);
				if(f)break;
			}

			else if(s[k]=='<'||(s[k]-'0'<0&&s[k] != '<')){

				continue;
			}
			else{
				c[s[k]-'0']++;
				s[k]=s[k]--;
			}
		//}
	}
}
int main(){
	scanf("%d%d",&n,&q);
	scanf("%s",s);

	memcpy(s2, s, sizeof(s2));
	for(int i=0;i<q;i++){
		scanf("%d%d",&l,&r);
		memcpy(s,s2,sizeof(s));
			f=0;
		memset(c,0,sizeof(c));
		R(l-1);
		for(int i=0;i<9;i++){
			printf("%d ",c[i]);
		}
		printf("%d\n",c[9]);
	}
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<cstring>

using namespace std;

int n,q,l,r,f;
char s[500];char s2[500];
int c[10];
void L(int k);
bool end(int a){
	for(;a<r;a++){
		if(s[a]-'0'>=0&&s[a]-'0'<10){
			return true;
		}
		else if(s[a]=='<')return false;
	}
	//return false;
}

void R(int j){
	for(;j>=l-1&&j<r;j++){

		//if(end(j)){
			if(s[j]=='>'){
				if(!end(j)){
				f=1;break;
				}
				else
				continue;
			}
			else if(s[j]=='c'){
				continue;
			}
			else if(s[j]=='<'){
				L(j);
			}
			else{
				c[s[j]-'0']++;
				if(s[j]=='0')s[j]='c';
				else
				s[j]=s[j]--;
			}
		//}
	}
}
void L(int k){
	for(;k>=l-1&&k<r;k--){
		//if(end(k)){
			if(s[k]=='>'){
				R(k);
				if(f)break;
			}

			else if(s[k]=='<'||s[k]=='c'){

				continue;
			}
			else{
				c[s[k]-'0']++;
				if(s[k]=='0')s[k]='c';
				else
				s[k]=s[k]--;
			}
		//}
	}
}
int main(){
	scanf("%d%d",&n,&q);
	scanf("%s",s);

	memcpy(s2, s, sizeof(s2));
	for(int i=0;i<q;i++){
		scanf("%d%d",&l,&r);
		memcpy(s,s2,sizeof(s));
			f=0;
		memset(c,0,sizeof(c));
		R(l-1);
		for(int i=0;i<9;i++){
			printf("%d ",c[i]);
		}
		printf("%d\n",c[9]);
	}
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<cstring>

using namespace std;

int n,q,l,r,f;
char s[500];char s2[500];
int c[10];
void L(int k);
bool end(int a){
	for(;a<r;a++){
		if(s[a]-'0'>=0&&s[a]-'0'<10){
			return true;
		}
		else if(s[a]=='<')return false;
	}
	return false;
}

void R(int j){
	for(;j>=l-1&&j<r;j++){

		//if(end(j)){
			if(s[j]=='>'){
				if(!end(j)){
				f=1;break;
				}
				else
				continue;
			}
			else if(s[j]=='c'){
				continue;
			}
			else if(s[j]=='<'){
				L(j);
				break;
			}
			else{
				c[s[j]-'0']++;
				if(s[j]=='0')s[j]='c';
				else
				s[j]--;
			}
		//}
	}
}
void L(int k){
	for(;k>=l-1&&k<r;k--){
		//if(end(k)){
			if(s[k]=='>'){
				R(k);
				break;
			}

			else if(s[k]=='<'||s[k]=='c'){
				continue;
			}
			else{
				c[s[k]-'0']++;
				if(s[k]=='0')s[k]='c';
				else
				s[k]--;
			}
		//}
	}
}
int main(){
	//while(~scanf("%d%d",&n,&q))	{
		scanf("%s",s);

		memcpy(s2, s, sizeof(s2));
		for(int i=0;i<q;i++){
			scanf("%d%d",&l,&r);
			memcpy(s,s2,sizeof(s));
				f=0;
			memset(c,0,sizeof(c));
			R(l-1);
			for(int i=0;i<9;i++){
				printf("%d ",c[i]);
			}
			printf("%d\n",c[9]);
		}
	//}
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<cstring>

using namespace std;

int n,q,l,r,f;
char s[500];char s2[500];
int c[10];
void L(int k);
bool end(int a){
	for(;a<r;a++){
		if(s[a]-'0'>=0&&s[a]-'0'<10){
			return true;
		}
		else if(s[a]=='<')return false;
	}
	return false;
}

void R(int j){
	for(;j>=l-1&&j<r;j++){

		//if(end(j)){
			if(s[j]=='>'){
				if(!end(j)){
				f=1;break;
				}
				else
				continue;
			}
			else if(s[j]=='c'){
				continue;
			}
			else if(s[j]=='<'){
				L(j);
				break;
			}
			else{
				c[s[j]-'0']++;
				if(s[j]=='0')s[j]='c';
				else
				s[j]--;
			}
		//}
	}
}
void L(int k){
	for(;k>=l-1&&k<r;k--){
		//if(end(k)){
			if(s[k]=='>'){
				R(k);
				if(f)break;
			}

			else if(s[k]=='<'||s[k]=='c'){
				continue;
			}
			else{
				c[s[k]-'0']++;
				if(s[k]=='0')s[k]='c';
				else
				s[k]--;
			}
		//}
	}
}
int main(){
	while(~scanf("%d%d",&n,&q))	{
		scanf("%s",s);

		memcpy(s2, s, sizeof(s2));
		for(int i=0;i<q;i++){
			scanf("%d%d",&l,&r);
			memcpy(s,s2,sizeof(s));
				f=0;
			memset(c,0,sizeof(c));
			R(l-1);
			for(int i=0;i<9;i++){
				printf("%d ",c[i]);
			}
			printf("%d\n",c[9]);
		}
	}
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<cstring>

using namespace std;

int n,q,l,r,f;
char s[500];char s2[500];
int c[10];
void L(int k);
bool end(int a){
	for(;a<r;a++){
		if(s[a]-'0'>=0&&s[a]-'0'<10){
			return true;
		}
		else if(s[a]=='<')return false;
	}
	return false;
}

void R(int j){
	for(;j>=l-1&&j<r;j++){

		//if(end(j)){
			if(s[j]=='>'){
				if(!end(j)){
				f=1;break;
				}
				else
				continue;
			}
			else if(s[j]=='c'){
				continue;
			}
			else if(s[j]=='<'){
				L(j);
			}
			else{
				c[s[j]-'0']++;
				if(s[j]=='0')s[j]='c';
				else
				s[j]--;
			}
		//}
	}
}
void L(int k){
	for(;k>=l-1&&k<r;k--){
		//if(end(k)){
			if(s[k]=='>'){
				R(k);
				if(f)break;
			}

			else if(s[k]=='<'||s[k]=='c'){

				continue;
			}
			else{
				c[s[k]-'0']++;
				if(s[k]=='0')s[k]='c';
				else
				s[k]=s[k]--;
			}
		//}
	}
}
int main(){
	while(~scanf("%d%d",&n,&q))	{
		scanf("%s",s);

		memcpy(s2, s, sizeof(s2));
		for(int i=0;i<q;i++){
			scanf("%d%d",&l,&r);
			memcpy(s,s2,sizeof(s));
				f=0;
			memset(c,0,sizeof(c));
			R(l-1);
			for(int i=0;i<9;i++){
				printf("%d ",c[i]);
			}
			printf("%d\n",c[9]);
		}
	}
	return 0;
}


import java.io.*;
import java.util.*;

public class DD {
    public static void main(String[] args) throws Exception {
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        int t = Integer.parseInt(buffer.readLine());
        while (t-- > 0) {
            int n = Integer.parseInt(buffer.readLine());
            char[]s = new char[n];
            String inp = buffer.readLine();
            for (int i = 0; i < n; i++) {
                s[i] = inp.charAt(i);
            }
            int cnt = 0;
            ArrayList<Integer>arrayList = new ArrayList<>();
            int temp = 1;
            char prev = s[0];

            for (int pos = 1; pos < n; pos++) {
                if (s[pos]==prev){
                    temp++;
                }
                else {
                    arrayList.add(temp);
                    temp = 1;
                    prev = s[pos];
                }
            }
            if (arrayList.size()==0)
                cnt = (temp+2)/3;
            else if (s[0]==s[n-1])
                arrayList.set(0, arrayList.get(0)+temp);
            else
                arrayList.add(temp);
            for (int sum:arrayList)
                cnt += sum/3;
//            System.out.println(Arrays.toString(s));
            sb.append(cnt+"\n");
        }
        System.out.println(sb);
    }
}