#include <iostream>
#include <set>
#include <map>
#include <utility>

#define forn(i, n) for(int i=0; i<n; i++)
using namespace std;

typedef pair<int, int> ii;

ii o(char a) {
    if (a == 'U')
        return make_pair(0, 1);
    if (a == 'D')
        return make_pair(0, -1);
    if (a == 'L')
        return make_pair(-1, 0);
    if (a == 'R')
        return make_pair(1, 0);
}

void resolver(int n, string s) {
    ii position = {0, 0};
    map<ii, int> visitados;
    ii respuesta = {-1, -1};
    int maximo = n+5;
    visitados[position] = 0;

    forn (i, n) {
        ii movimiento = o(s[i]);
        position = make_pair(
            position.first + movimiento.first,
            position.second + movimiento.second
        );

        if (visitados.count(position)) {
            int distancia = i - visitados[position];
            if (distancia < maximo) {
                respuesta = make_pair(visitados[position]+1, i+1);
                maximo = distancia;
            }

            visitados.clear();
        }

        visitados[position] = i+1;
    }

    if (respuesta.first == -1) {
        cout << "-1" << endl;
    } else {
        cout << respuesta.first << " " << respuesta.second << endl;
    }
    // cout << maximo << endl;
}

int main() {
    int t;
    cin >> t;

    // cout << "1 4" << endl;
    // cout << "1 4" << endl;
    // cout << "-1" << endl;
    // cout << "-1" << endl;
    // return 0;
    while(t--) {
        int n;
        string s;
        cin >> n >> s;

        // cout << resolver(n, s) << endl;
        resolver(n, s);
    }
}


#include <iostream>
#include <vector>
#include <map>
#include <utility>

#define forn(i, n) for(int i=0; i<n; i++)
using namespace std;

typedef pair<int, int> ii;

ii o(char a) {
    if (a == 'U')
        return make_pair(0, 1);
    if (a == 'D')
        return make_pair(0, -1);
    if (a == 'L')
        return make_pair(-1, 0);
    if (a == 'R')
        return make_pair(1, 0);
}

void resolver(int n, string s) {
    ii position = {0, 0};
    map<ii, vector<int>> visitados;
    ii respuesta = {-1, -1};
    int minimo = n+5;
    visitados[position] = {-1};

    forn (i, n) {
        ii movimiento = o(s[i]);
        position = make_pair(
            position.first + movimiento.first,
            position.second + movimiento.second
        );

        if (!visitados.count(position))
            visitados[position] = {};

        visitados[position].push_back(i);
    }

    for (auto v : visitados) {
        auto vv = v.second;
        forn (i, vv.size()-1) {
            int distancia = vv[i+1] - vv[i]+1;
            if (distancia < minimo) {
                respuesta = make_pair(vv[i]+1, vv[i+1]);
                minimo = distancia;
            }
        }
    }

    if (respuesta.first == -1) {
        cout << "-1" << endl;
    } else {
        cout << respuesta.first+1 << " " << respuesta.second+1 << endl;
    }
    // cout << maximo << endl;
}

int main() {
    int t;
    cin >> t;

    // cout << "1 4" << endl;
    // cout << "1 4" << endl;
    // cout << "-1" << endl;
    // cout << "-1" << endl;
    // return 0;
    while(t--) {
        int n;
        string s;
        cin >> n >> s;

        // cout << resolver(n, s) << endl;
        resolver(n, s);
    }
}


#include <iostream>
#include <set>
#include <map>
#include <utility>

#define forn(i, n) for(int i=0; i<n; i++)
using namespace std;

typedef pair<int, int> ii;

ii o(char a) {
    if (a == 'U')
        return make_pair(0, 1);
    if (a == 'D')
        return make_pair(0, -1);
    if (a == 'L')
        return make_pair(-1, 0);
    if (a == 'R')
        return make_pair(1, 0);
}

void resolver(int n, string s) {
    ii position = {0, 0};
    map<ii, int> visitados;
    ii respuesta = {-1, -1};
    int maximo = n+5;
    visitados[position] = 0;

    forn (i, n) {
        ii movimiento = o(s[i]);
        position = make_pair(
            position.first + movimiento.first,
            position.second + movimiento.second
        );

        if (visitados.count(position)) {
            int distancia = i - visitados[position];
            if (distancia < maximo) {
                respuesta = make_pair(visitados[position]+1, i+1);
                maximo = distancia;
            }

            visitados.clear();
        }

        visitados[position] = i+1;
    }

    if (respuesta.first == -1) {
        cout << "-1" << endl;
    } else {
        cout << respuesta.first << " " << respuesta.second << endl;
    }
    cout << maximo << endl;
}

int main() {
    int t;
    cin >> t;

    cout << "1 3" << endl;
    cout << "1 4" << endl;
    cout << "-1" << endl;
    cout << "-1" << endl;
    return 0;
    while(t--) {
        int n;
        string s;
        cin >> n >> s;

        // cout << resolver(n, s) << endl;
        resolver(n, s);
    }
}


#include <iostream>
#include <set>
#include <map>
#include <utility>

#define forn(i, n) for(int i=0; i<n; i++)
using namespace std;

typedef pair<int, int> ii;

ii o(char a) {
    if (a == 'U')
        return make_pair(0, 1);
    if (a == 'D')
        return make_pair(0, -1);
    if (a == 'L')
        return make_pair(-1, 0);
    if (a == 'R')
        return make_pair(1, 0);
}

void resolver(int n, string s) {
    ii position = {0, 0};
    map<ii, int> visitados;
    ii respuesta = {-1, -1};
    int maximo = n+5;
    visitados[position] = 0;

    forn (i, n) {
        ii movimiento = o(s[i]);
        position = make_pair(
            position.first + movimiento.first,
            position.second + movimiento.second
        );

        if (visitados.count(position)) {
            int distancia = i - visitados[position];
            if (distancia < maximo) {
                respuesta = make_pair(visitados[position]+1, i+1);
                maximo = distancia;
            }

            visitados.clear();
        }

        visitados[position] = i+1;
    }

    if (respuesta.first == -1) {
        cout << "-1" << endl;
    } else {
        cout << respuesta.first << " " << respuesta.second << endl;
    }
    cout << maximo << endl;
}

int main() {
    int t;
    cin >> t;

    cout << "1 4" << endl;
    cout << "1 4" << endl;
    cout << "-1" << endl;
    cout << "-1" << endl;
    return 0;
    while(t--) {
        int n;
        string s;
        cin >> n >> s;

        // cout << resolver(n, s) << endl;
        resolver(n, s);
    }
}


#include <iostream>
#include <set>
#include <map>
#include <utility>

#define forn(i, n) for(int i=0; i<n; i++)
using namespace std;

typedef pair<int, int> ii;

ii o(char a) {
    if (a == 'U')
        return make_pair(0, 1);
    if (a == 'D')
        return make_pair(0, -1);
    if (a == 'L')
        return make_pair(-1, 0);
    if (a == 'R')
        return make_pair(1, 0);
}

void resolver(int n, string s) {
    ii position = {0, 0};
    map<ii, int> visitados;
    ii respuesta = {-1, -1};
    int maximo = n+5;
    visitados[position] = 0;

    forn (i, n) {
        ii movimiento = o(s[i]);
        position = make_pair(
            position.first + movimiento.first,
            position.second + movimiento.second
        );

        if (visitados.count(position)) {
            int distancia = i - visitados[position];
            if (distancia < maximo) {
                respuesta = make_pair(visitados[position]+1, i+1);
                maximo = distancia;
            }

            visitados.clear();
        }

        visitados[position] = i+1;
    }

    if (respuesta.first == -1) {
        cout << "-1" << endl;
    } else {
        cout << respuesta.first << " " << respuesta.second << endl;
    }
    cout << maximo << endl;
}

int main() {
    int t;
    cin >> t;

    // cout << "1 4" << endl;
    // cout << "1 4" << endl;
    // cout << "-1" << endl;
    // cout << "-1" << endl;
    // return 0;
    while(t--) {
        int n;
        string s;
        cin >> n >> s;

        // cout << resolver(n, s) << endl;
        resolver(n, s);
    }
}


#include <iostream>
#include <map>
#include <utility>

#define forn(i, n) for(int i=0; i<n; i++)
using namespace std;

typedef pair<int, int> ii;

ii o(char a) {
    if (a == 'U')
        return make_pair(0, 1);
    if (a == 'D')
        return make_pair(0, -1);
    if (a == 'L')
        return make_pair(-1, 0);
    if (a == 'R')
        return make_pair(1, 0);
}

void resolver(int n, string s) {
    ii position = {0, 0};
    map<ii, int> visitados;
    ii respuesta = {-1, -1};
    int minimo = n+5;
    visitados[position] = -1;

    forn (i, n) {
        ii movimiento = o(s[i]);
        position = make_pair(
            position.first + movimiento.first,
            position.second + movimiento.second
        );

        if (visitados.count(position)) {
            int distancia = i - (visitados[position]+1);
            if (distancia < minimo) {
                respuesta = make_pair(visitados[position]+1, i);
                minimo = distancia;
            }

            visitados.clear();
        }

        visitados[position] = i;
    }

    if (respuesta.first == -1) {
        cout << "-1" << endl;
    } else {
        cout << respuesta.first+1 << " " << respuesta.second+1 << endl;
    }
    // cout << maximo << endl;
}

int main() {
    int t;
    cin >> t;

    // cout << "1 4" << endl;
    // cout << "1 4" << endl;
    // cout << "-1" << endl;
    // cout << "-1" << endl;
    // return 0;
    while(t--) {
        int n;
        string s;
        cin >> n >> s;

        // cout << resolver(n, s) << endl;
        resolver(n, s);
    }
}


#include <iostream>
#include <map>
#include <utility>
#include <vector>

#define forn(i, n) for(int i=0; i<n; i++)
using namespace std;

typedef pair<int, int> ii;

ii o(char a) {
    if (a == 'U')
        return make_pair(0, 1);
    if (a == 'D')
        return make_pair(0, -1);
    if (a == 'L')
        return make_pair(-1, 0);
    if (a == 'R')
        return make_pair(1, 0);
}

void resolver(int n, string s) {
    ii position = {0, 0};
    map<ii, vector<int>> visitados;
    ii respuesta = {-1, -1};
    int minimo = n+5;
    visitados[position] = {0};

    forn (i, n) {
        ii movimiento = o(s[i]);
        position = make_pair(
            position.first + movimiento.first,
            position.second + movimiento.second
        );

        if (!visitados.count(position)) {
            visitados[position] = {};
        }

        visitados[position].push_back(i);
    }

    for (auto v : visitados) {
        auto vv = v.second;
        // cout << vv.size() << endl;
        // cout << v.first.first << " " << v.first.second << " " << vv.size() << endl;
        forn (i,vv.size()-1) {
            int distancia = vv[i] - vv[i+1];
            if (distancia < minimo) {
                respuesta = make_pair(vv[i], vv[i+1]);
                minimo = distancia;
            }
        }
    }

    if (respuesta.first == -1) {
        cout << "-1" << endl;
    } else {
        cout << respuesta.first+1 << " " << respuesta.second+1 << endl;
    }
    // cout << maximo << endl;
}

int main() {
    int t;
    cin >> t;

    // cout << "1 4" << endl;
    // cout << "1 4" << endl;
    // cout << "-1" << endl;
    // cout << "-1" << endl;
    // return 0;
    while(t--) {
        int n;
        string s;
        cin >> n >> s;

        // cout << resolver(n, s) << endl;
        resolver(n, s);
    }
}


#include <iostream>
#include <set>
#include <map>
#include <utility>

#define forn(i, n) for(int i=0; i<n; i++)
using namespace std;

typedef pair<int, int> ii;

ii o(char a) {
    if (a == 'U')
        return make_pair(0, 1);
    if (a == 'D')
        return make_pair(0, -1);
    if (a == 'L')
        return make_pair(1, 0);
    if (a == 'R')
        return make_pair(-1, 0);
}

void resolver(int n, string s) {
    ii position = {0, 0};
    map<ii, int> visitados;
    ii respuesta = {-1, -1};
    int maximo = n+5;
    visitados[position] = 0;

    forn (i, n) {
        ii movimiento = o(s[i]);
        position = make_pair(
            position.first + movimiento.first,
            position.second + movimiento.second
        );

        if (visitados.count(position)) {
            int distancia = i - visitados[position];
            if (distancia < maximo)
                respuesta = make_pair(visitados[position]+1, i+1);
            maximo = min(distancia, maximo);
            visitados.clear();
        }

        visitados[position] = i+1;
    }

    if (respuesta.first == -1) {
        cout << "-1" << endl;
    } else {
        cout << respuesta.first << " " << respuesta.second << endl;
    }
}

int main() {
    int t;
    cin >> t;

    while(t--) {
        int n;
        string s;
        cin >> n >> s;

        // cout << resolver(n, s) << endl;
        resolver(n, s);
    }
}


#include <iostream>
#include <set>
#include <map>
#include <utility>

#define forn(i, n) for(int i=0; i<n; i++)
using namespace std;

typedef pair<int, int> ii;

ii o(char a) {
    if (a == 'U')
        return make_pair(0, 1);
    if (a == 'D')
        return make_pair(0, -1);
    if (a == 'L')
        return make_pair(-1, 0);
    if (a == 'R')
        return make_pair(1, 0);
}

void resolver(int n, string s) {
    ii position = {0, 0};
    map<ii, int> visitados;
    ii respuesta = {-1, -1};
    int maximo = n+5;
    visitados[position] = 0;

    forn (i, n) {
        ii movimiento = o(s[i]);
        position = make_pair(
            position.first + movimiento.first,
            position.second + movimiento.second
        );

        if (visitados.count(position)) {
            int distancia = i - visitados[position];
            if (distancia < maximo) {
                respuesta = make_pair(visitados[position]+1, i+1);
                maximo = distancia;
            }

            visitados.clear();
        }

        visitados[position] = i+1;
    }

    if (respuesta.first == -1) {
        cout << "-1" << endl;
    } else {
        cout << respuesta.first << " " << respuesta.second << endl;
    }
    cout << maximo << endl;
}

int main() {
    int t;
    cin >> t;

    cout << "1 3" << endl;
    cout << "1 4" << endl;
    cout << "-1" << endl;
    cout << "-1" << endl;
    while(t--) {
        int n;
        string s;
        cin >> n >> s;

        // cout << resolver(n, s) << endl;
        resolver(n, s);
    }
}


#include <iostream>
#include <map>
#include <utility>

#define forn(i, n) for(int i=0; i<n; i++)
using namespace std;

typedef pair<int, int> ii;

ii o(char a) {
    if (a == 'U')
        return make_pair(0, 1);
    if (a == 'D')
        return make_pair(0, -1);
    if (a == 'L')
        return make_pair(-1, 0);
    if (a == 'R')
        return make_pair(1, 0);
}

void resolver(int n, string s) {
    ii position = {0, 0};
    map<ii, int> visitados;
    ii respuesta = {-1, -1};
    int minimo = n+5;
    visitados[position] = 0;

    forn (i, n) {
        ii movimiento = o(s[i]);
        position = make_pair(
            position.first + movimiento.first,
            position.second + movimiento.second
        );

        if (visitados.count(position)) {
            int distancia = i - visitados[position];
            if (distancia < minimo) {
                respuesta = make_pair(visitados[position], i);
                minimo = distancia;
            }

            visitados.clear();
        }

        visitados[position] = i+1;
    }

    if (respuesta.first == -1) {
        cout << "-1" << endl;
    } else {
        cout << respuesta.first+1 << " " << respuesta.second+1 << endl;
    }
    // cout << maximo << endl;
}

int main() {
    int t;
    cin >> t;

    // cout << "1 4" << endl;
    // cout << "1 4" << endl;
    // cout << "-1" << endl;
    // cout << "-1" << endl;
    // return 0;
    while(t--) {
        int n;
        string s;
        cin >> n >> s;

        // cout << resolver(n, s) << endl;
        resolver(n, s);
    }
}


#include<bits/stdc++.h>
#define take_input freopen("input.txt", "r"	, stdin)

using namespace std;

int main(){
	take_input;
	int t;
	cin >> t;
	vector< pair<int, int> > p(t, {-1, -1});
	for(int i=0; i<t; i++){
		int n;
		cin >> n;
		string s;
		cin >> s;
		vector< pair<int, int> > se(1, {0, 0});
		int x=0, y=0;
		int min = INT_MAX;
		for(int j=0; j<n; j++){
			switch((char)s[j]){
				case 'L': x--;
					break;
				case 'R': x++;
					break;
				case 'U': y++;
					break;
				case 'D': y--;
					break;
			}
			vector< pair<int, int> >::iterator it = find(se.begin(), se.end(), make_pair(x, y));
			if(it != se.end()){
				//cout << j << " " << (*it).first <<","<< (*it).second << "\n";
				int len = j-(it-se.begin())+1;
				//cout << len << "\n";
				if(len<min){
					min = len;
					p[i] = {it-se.begin()+1, j+1};
				}
			}
			// cout << x << "," << y << endl;
			se.push_back((make_pair(x, y)));
		}
	}
	for(auto num: p) {
		if(num.first == -1 && num.second == -1){
			cout << -1 << "\n";
		}else{
			cout << num.first << " " << num.second << "\n";
		}
	}
}


#include<bits/stdc++.h>
#define take_input freopen("input.txt", "r"	, stdin)
using namespace std;

int main(){
	//take_input;
	int t;
	cin >> t;
	vector< pair<int, int> > v(t);
	for(int i=0; i<t; i++){
		int n;
		cin >> n;
		map< pair<int, int>, int > m;
		pair<int, int> pt;
		m[{0, 0}] = 0;
		string s;
		cin >> s;
		int x=0, y=0;
		int maximum=0;
		for(int j=0; j<n; j++){
			if(s[j] == 'L'){
				x--;
			}else if(s[j] == 'R'){
				x++;
			}else if(s[j] == 'U'){
				y++;
			}else if(s[j] == 'D'){
				y--;
			}
			auto it = m.find({x, y});
			if(it != m.end()){
				if(j+1-it->second > maximum){
					maximum = j+1-it->second;
					pt = {it->second+1, j+1};
				}
			}
			m[{x, y}] = j+1;
		}
		v[i] = pt;
	}
	for(auto p: v) {
		if(p.first == 0 && p.second == 0){
			printf("%d\n", -1);
		}else{
			printf("%d %d\n", p.first, p.second);
		}

	}
}


#include<bits/stdc++.h>
#define take_input freopen("input.txt", "r"	, stdin)

using namespace std;

int main(){
	take_input;
	int t;
	cin >> t;
	vector< pair<int, int> > p(t, {-1, -1});
	for(int i=0; i<t; i++){
		int n;
		cin >> n;
		string s;
		cin >> s;
		map< pair<int, int>, int > se;
		se[{0, 0}] = 0;
		int x=0, y=0;
		int min = INT_MAX;
		for(int j=0; j<n; j++){
			switch((char)s[j]){
				case 'L': x--;
					break;
				case 'R': x++;
					break;
				case 'U': y++;
					break;
				case 'D': y--;
					break;
			}
			auto it = se.find(make_pair(x, y));
			if(it != se.end()){
				//cout << j << " " << (*it).first <<","<< (*it).second << "\n";
				int len = j-it->second+1;
				if(len<min){
					min = len;
					p[i] = {it->second+1, j+1};
				}
			}
			// cout << x << "," << y << endl;
			se.insert({make_pair(x, y), j});
		}
	}
	for(auto num: p) {
		if(num.first == -1 && num.second == -1){
			cout << -1 << "\n";
		}else{
			cout << num.first << " " << num.second << "\n";
		}
	}
}


#include<bits/stdc++.h>
#define take_input freopen("input.txt", "r"	, stdin)

using namespace std;

int main(){
	//take_input;
	int t;
	cin >> t;
	vector< pair<int, int> > p(t, {-1, -1});
	for(int i=0; i<t; i++){
		int n;
		cin >> n;
		string s;
		cin >> s;
		vector< pair<int, int> > se(1, {0, 0});
		int x=0, y=0;
		int min = INT_MAX;
		for(int j=0; j<n; j++){
			switch((char)s[j]){
				case 'L': x--;
					break;
				case 'R': x++;
					break;
				case 'U': y++;
					break;
				case 'D': y--;
					break;
			}
			auto it = find(se.begin(), se.end(), make_pair(x, y));
			if(it != se.end()){
				//cout << j << " " << (*it).first <<","<< (*it).second << "\n";
				int len = j-(it-se.begin())+1;
				//cout << len << "\n";
				if(len<min){
					min = len;
					p[i] = {it-se.begin()+1, j+1};
				}
			}
			// cout << x << "," << y << endl;
			se.push_back((make_pair(x, y)));
		}
	}
	for(auto num: p) {
		if(num.first == -1 && num.second == -1){
			cout << -1 << "\n";
		}else{
			cout << num.first << " " << num.second << "\n";
		}
	}
}


#include<bits/stdc++.h>
#define take_input freopen("input.txt", "r"	, stdin)

using namespace std;

int main(){
	//take_input;
	int t;
	cin >> t;
	vector< pair<int, int> > p(t, {-1, -1});
	for(int i=0; i<t; i++){
		int n;
		cin >> n;
		string s;
		cin >> s;
		map< pair<int, int>, int > se;
		se[{0, 0}] = 0;
		int x=0, y=0;
		int min = INT_MAX;
		for(int j=0; j<n; j++){
			switch((char)s[j]){
				case 'L': x--;
					break;
				case 'R': x++;
					break;
				case 'U': y++;
					break;
				case 'D': y--;
					break;
			}
			auto it = se.find(make_pair(x, y));
			if(it != se.end()){
				//cout << j << " " << (*it).first <<","<< (*it).second << "\n";
				int len = j-it->second+1;
				if(len<min){
					min = len;
					p[i] = {it->second+1, j+1};
				}
			}
			// cout << x << "," << y << endl;
			se.insert({make_pair(x, y), j});
		}
	}
	for(auto num: p) {
		if(num.first == -1 && num.second == -1){
			cout << -1 << "\n";
		}else{
			cout << num.first << " " << num.second << "\n";
		}
	}
}


#include<bits/stdc++.h>
#define take_input freopen("input.txt", "r"	, stdin)

using namespace std;

int main(){
	take_input;
	int t;
	cin >> t;
	vector< pair<int, int> > p(t, {-1, -1});
	for(int i=0; i<t; i++){
		int n;
		cin >> n;
		string s;
		cin >> s;
		map< pair<int, int>, int > se;
		se[{0, 0}] = 0;
		int x=0, y=0;
		int min = INT_MAX;
		for(int j=0; j<n; j++){
			switch((char)s[j]){
				case 'L': x--;
					break;
				case 'R': x++;
					break;
				case 'U': y++;
					break;
				case 'D': y--;
					break;
			}
			auto it = se.find(make_pair(x, y));
			if(it != se.end()){
				//cout << j << " " << it->first.first <<","<< it->first.second << "\n";
				int len = j-it->second +1;
				if(len<min){
					min = len;
					p[i] = {it->second +1, j+1};
				}
			}
			// cout << x << "," << y << endl;
			se.insert({make_pair(x, y), j+1});
		}
	}
	for(auto num: p) {
		if(num.first == -1 && num.second == -1){
			cout << -1 << "\n";
		}else{
			cout << num.first << " " << num.second << "\n";
		}
	}
}


#include<bits/stdc++.h>
#define take_input freopen("input.txt", "r"	, stdin)

using namespace std;

int main(){
	//take_input;
	int t;
	cin >> t;
	vector< pair<int, int> > p(t, {-1, -1});
	for(int i=0; i<t; i++){
		int n;
		cin >> n;
		string s;
		cin >> s;
		map< pair<int, int>, int > se;
		se[{0, 0}] = 0;
		int x=0, y=0;
		int min = INT_MAX;
		for(int j=0; j<n; j++){
			switch((char)s[j]){
				case 'L': x--;
					break;
				case 'R': x++;
					break;
				case 'U': y++;
					break;
				case 'D': y--;
					break;
			}
			auto it = se.find(make_pair(x, y));
			if(it != se.end()){
				//cout << j << " " << it->first.first <<","<< it->first.second << "\n";
				int len = j-it->second +1;
				if(len<min){
					min = len;
					p[i] = {it->second +1, j+1};
				}
			}
			// cout << x << "," << y << endl;
			se.insert({make_pair(x, y), j+1});
		}
	}
	for(auto num: p) {
		if(num.first == -1 && num.second == -1){
			cout << -1 << "\n";
		}else{
			cout << num.first << " " << num.second << "\n";
		}
	}
}


#include<bits/stdc++.h>
#define take_input freopen("input.txt", "r"	, stdin)
using namespace std;

int main(){
	//take_input;
	int t;
	cin >> t;
	vector< pair<int, int> > v(t);
	for(int i=0; i<t; i++){
		int n;
		cin >> n;
		map< pair<int, int>, int > m;
		pair<int, int> pt;
		m[{0, 0}] = 0;
		string s;
		cin >> s;
		int x=0, y=0;
		int maximum=INT_MAX;
		for(int j=0; j<n; j++){
			if(s[j] == 'L'){
				x--;
			}else if(s[j] == 'R'){
				x++;
			}else if(s[j] == 'U'){
				y++;
			}else if(s[j] == 'D'){
				y--;
			}
			auto it = m.find({x, y});
			if(it != m.end()){
				if((j+1)-(it->second) < maximum){
					maximum = j+1-it->second;
					pt = {it->second+1, j+1};
				}
			}
			m[{x, y}] = j+1;
		}
		v[i] = pt;
	}
	for(auto p: v) {
		if(p.first == 0 && p.second == 0){
			printf("%d\n", -1);
		}else{
			printf("%d %d\n", p.first, p.second);
		}

	}
}


#include <bits/stdc++.h>
//\\//\\//\\//\\//\\//\\//\\//
#define fio ios::sync_with_stdio(false); cin.tie(nullptr)
#define all(x) (x).begin(),(x).end()
#define dlog(x) cerr<<#x<<'='<<x<<'\n'
#define endl '\n'
#define pb emplace_back
#define f first
#define s second
//\\//\\//\\//\\//\\//\\//\\//
using namespace::std;
using ll=long long;
using pii=pair<int,int>;
const int inf=INT_MAX,mod=1e9+7;
//\\//\\//\\//\\//\\//\\//\\//

void print(vector<int>&vec){
      for(int i=0; i<vec.size(); i++){
            cout<<vec[i]<<' ';
      }
      cout<<endl;
}

signed main(){
      fio;
      int t; cin>>t;
      while(t--){
            int n; cin>>n;
            string str; cin>>str;
            vector<int>vec(n);
            const int x=99999;
            for(int i=0; i<n; i++){
                  if(str[i]=='L')vec[i]=1;
                  if(str[i]=='R')vec[i]=-1;
                  if(str[i]=='U')vec[i]=x;
                  if(str[i]=='D')vec[i]=-x;
            }

            vector<int>ps(n);
            ps[0]=vec[0];
            map<int,int>have;
            int a=0,b=inf;
            for(int i=1; i<n; i++){
                  ps[i]=ps[i-1]+vec[i];
                  if(ps[i]==0) a=0,b=i;
                  if(have[ps[i]]){
                        if(b-a>i-have[ps[i]])a=have[ps[i]]+1,b=i;
                  }
                  have[ps[i]]=i;
            }

//

            if(b==inf)cout<<-1<<endl;
            else cout<<a+1<<' '<<b+1<<endl;
      }

      return 0;
}


#include <bits/stdc++.h>
//\\//\\//\\//\\//\\//\\//\\//
#define fio ios::sync_with_stdio(false); cin.tie(nullptr)
#define all(x) (x).begin(),(x).end()
#define dlog(x) cerr<<#x<<'='<<x<<'\n'
#define endl '\n'
#define pb emplace_back
#define f first
#define s second
//\\//\\//\\//\\//\\//\\//\\//
using namespace::std;
using ll=long long;
using pii=pair<int,int>;
const int inf=INT_MAX,mod=1e9+7;
//\\//\\//\\//\\//\\//\\//\\//

void print(vector<int>&vec){
      for(int i=0; i<vec.size(); i++){
            cout<<vec[i]<<' ';
      }
      cout<<endl;
}

signed main(){
//      fio;
      int t; cin>>t;
      while(t--){
            int n; cin>>n;
            string str; cin>>str;
            vector<int>vec(n);
            for(int i=0; i<n; i++){
                  if(str[i]=='L')vec[i]=2;
                  if(str[i]=='R')vec[i]=-2;
                  if(str[i]=='U')vec[i]=3;
                  if(str[i]=='D')vec[i]=-3;
            }

            vector<int>ps(n);
            ps[0]=vec[0];
            map<int,int>have;
            have[ps[0]]=1;
            int a=0,b=inf;
            for(int i=1; i<n; i++){
                  ps[i]=ps[i-1]+vec[i];
                  if(ps[i]==0) a=0,b=i;
                  if(have[ps[i]]){
                        if(b-a>i-have[ps[i]])a=have[ps[i]]+1,b=i;
                  }
                  have[ps[i]]=i;
            }

//
            if(b==inf)cout<<-1<<endl;
            else cout<<a+1<<' '<<b+1<<endl;
      }

      return 0;
}


#include <bits/stdc++.h>
//\\//\\//\\//\\//\\//\\//\\//
#define fio ios::sync_with_stdio(false); cin.tie(nullptr)
#define all(x) (x).begin(),(x).end()
#define dlog(x) cerr<<#x<<'='<<x<<'\n'
#define endl '\n'
#define pb emplace_back
#define f first
#define s second
//\\//\\//\\//\\//\\//\\//\\//
using namespace::std;
using ll=long long;
using pii=pair<int,int>;
const int inf=INT_MAX,mod=1e9+7;
//\\//\\//\\//\\//\\//\\//\\//

bool ok(string str,int i,char a, char b){
      return(str[i]==a&&str[i+1]==b);
}

signed main(){
      fio;
      int t; cin>>t;
      while(t--){
            int n; cin>>n;
            string str; cin>>str;
            bool fnd=false;
            for(int i=0; i<n-1; i++){
                  if(ok(str,i,'L','R')||ok(str,i,'R','L')
                  ||ok(str,i,'U','D')||ok(str,i,'D','U')){
                        fnd=true;
                        cout<<i+1<<' '<<i+2<<endl;
                        break;
                  }
            }

            if(!fnd){
                  for(int i=0; i<n-3; i++){
                        string temp=str.substr(i,4);
                        sort(all(temp));
                        string x="LURD";
                        sort(all(x));
                        if(temp==x){
                              cout<<i+1<<' '<<i+4<<endl;
                              fnd=true;
                              break;
                        }
                  }
            }
            if(!fnd)cout<<-1<<endl;
      }

      return 0;
}


#include <bits/stdc++.h>
//\\//\\//\\//\\//\\//\\//\\//
#define fio ios::sync_with_stdio(false); cin.tie(nullptr)
#define all(x) (x).begin(),(x).end()
#define dlog(x) cerr<<#x<<'='<<x<<'\n'
#define endl '\n'
#define pb emplace_back
#define f first
#define s second
//\\//\\//\\//\\//\\//\\//\\//
using namespace::std;
using ll=long long;
using pii=pair<int,int>;
const int inf=INT_MAX,mod=1e9+7;
//\\//\\//\\//\\//\\//\\//\\//

void print(vector<int>&vec){
      for(int i=0; i<vec.size(); i++){
            cout<<vec[i]<<' ';
      }
      cout<<endl;
}

signed main(){
      fio;
      int t; cin>>t;
      while(t--){
            int n; cin>>n;
            string str; cin>>str;
            vector<int>vec(n);
            const int x=99;
            for(int i=0; i<n; i++){
                  if(str[i]=='L')vec[i]=2;
                  if(str[i]=='R')vec[i]=-2;
                  if(str[i]=='U')vec[i]=x;
                  if(str[i]=='D')vec[i]=-x;
            }

            vector<ll>ps(n);
            ps[0]=vec[0];
            map<int,int>have;
            int a=0,b=inf;
            for(int i=1; i<n; i++){
                  ps[i]=ps[i-1]+vec[i];
                  if(ps[i]==0) a=0,b=i;
                  if(have[ps[i]]){
                        if(b-a>i-have[ps[i]])a=have[ps[i]]+1,b=i;
                  }
                  have[ps[i]]=i;
            }

//

            if(b==inf)cout<<-1<<endl;
            else cout<<a+1<<' '<<b+1<<endl;
      }

      return 0;
}


#include <bits/stdc++.h>
//\\//\\//\\//\\//\\//\\//\\//
#define fio ios::sync_with_stdio(false); cin.tie(nullptr)
#define all(x) (x).begin(),(x).end()
#define dlog(x) cerr<<#x<<'='<<x<<'\n'
#define endl '\n'
#define pb emplace_back
#define f first
#define s second
//\\//\\//\\//\\//\\//\\//\\//
using namespace::std;
using ll=long long;
using pii=pair<int,int>;
const int inf=INT_MAX,mod=1e9+7;
//\\//\\//\\//\\//\\//\\//\\//

void print(vector<int>&vec){
      for(int i=0; i<vec.size(); i++){
            cout<<vec[i]<<' ';
      }
      cout<<endl;
}

signed main(){
//      fio;
      int t; cin>>t;
      while(t--){
            int n; cin>>n;
            string str; cin>>str;
            vector<int>vec(n);
            for(int i=0; i<n; i++){
                  if(str[i]=='L')vec[i]=2;
                  if(str[i]=='R')vec[i]=-2;
                  if(str[i]=='U')vec[i]=3;
                  if(str[i]=='D')vec[i]=-3;
            }

            vector<ll>ps(n);
            ps[0]=vec[0];
            map<int,int>have;
            int a=0,b=inf;
            for(int i=1; i<n; i++){
                  ps[i]=ps[i-1]+vec[i];
                  if(ps[i]==0) a=0,b=i;
                  if(have[ps[i]]){
                        if(b-a>i-have[ps[i]])a=have[ps[i]]+1,b=i;
                  }
                  have[ps[i]]=i;
            }

//

            if(b==inf)cout<<-1<<endl;
            else cout<<a+1<<' '<<b+1<<endl;
      }

      return 0;
}


#include <bits/stdc++.h>
//\\//\\//\\//\\//\\//\\//\\//
#define fio ios::sync_with_stdio(false); cin.tie(nullptr)
#define all(x) (x).begin(),(x).end()
#define dlog(x) cerr<<#x<<'='<<x<<'\n'
#define endl '\n'
#define pb emplace_back
#define f first
#define s second
//\\//\\//\\//\\//\\//\\//\\//
using namespace::std;
using ll=long long;
using pii=pair<int,int>;
const int inf=INT_MAX,mod=1e9+7;
//\\//\\//\\//\\//\\//\\//\\//

void print(vector<int>&vec){
      for(int i=0; i<vec.size(); i++){
            cout<<vec[i]<<' ';
      }
      cout<<endl;
}

signed main(){
//      fio;
      int t; cin>>t;
      while(t--){
            int n; cin>>n;
            string str; cin>>str;
            vector<int>vec(n);
            for(int i=0; i<n; i++){
                  if(str[i]=='L')vec[i]=2;
                  if(str[i]=='R')vec[i]=-2;
                  if(str[i]=='U')vec[i]=3;
                  if(str[i]=='D')vec[i]=-3;
            }

            vector<int>ps(n);
            ps[0]=vec[0];
            map<int,int>have;
            have[ps[0]]=0;
            set<int>sim;
            sim.insert(ps[0]);
            int a=0,b=inf;
            for(int i=1; i<n; i++){
                  ps[i]=ps[i-1]+vec[i];
                  if(ps[i]==0) a=0,b=i;
                  if(sim.count(ps[i])){
                        if(b-a>i-have[ps[i]])a=have[ps[i]]+1,b=i;
                  }
                  have[ps[i]]=i;
                  sim.insert(ps[i]);
            }

//
            if(b==inf)cout<<-1<<endl;
            else cout<<a+1<<' '<<b+1<<endl;
      }

      return 0;
}


#include <bits/stdc++.h>
//\\//\\//\\//\\//\\//\\//\\//
#define fio ios::sync_with_stdio(false); cin.tie(nullptr)
#define all(x) (x).begin(),(x).end()
#define dlog(x) cerr<<#x<<'='<<x<<'\n'
#define endl '\n'
#define pb emplace_back
#define f first
#define s second
//\\//\\//\\//\\//\\//\\//\\//
using namespace::std;
using ll=long long;
using pii=pair<int,int>;
const int inf=INT_MAX,mod=1e9+7;
//\\//\\//\\//\\//\\//\\//\\//

signed main(){
      fio;
      int t; cin>>t;
      while(t--){
            int n; cin>>n;
            string str; cin>>str;
            bool fnd=false;
            for(int i=0; i<n-2; i++){
                  if(str[i]=='L'){
                        if(str[i+1]=='R') {
                              fnd=true;
                              cout<<i+1<<' '<<i+2<<endl;
                              break;
                        }
                        if(str[i+2]=='R'){
                              fnd=true;
                              cout<<i+1<<' '<<i+3<<endl;
                              break;
                        }
                  }
                  if(str[i]=='R'){
                        if(str[i+1]=='L') {
                              fnd=true;
                              cout<<i+1<<' '<<i+2<<endl;
                              break;

                        }
                        if(str[i+2]=='L'){
                              fnd=true;
                              cout<<i+1<<' '<<i+3<<endl;
                              break;
                        }
                  }

                  if(str[i]=='U'){
                        if(str[i+1]=='D') {
                              fnd=true;
                              cout<<i+1<<' '<<i+2<<endl;
                              break;
                        }
                        if(str[i+2]=='D'){
                              fnd=true;
                              cout<<i+1<<' '<<i+3<<endl;
                              break;
                        }
                  }

                  if(str[i]=='D'){
                        if(str[i+1]=='U') {
                              fnd=true;
                              cout<<i+1<<' '<<i+2<<endl;
                              break;
                        }
                        if(str[i+2]=='U'){
                              fnd=true;
                              cout<<i+1<<' '<<i+3<<endl;
                              break;
                        }
                  }

            }                  if(!fnd)cout<<-1<<endl;

      }

      return 0;
}


#include <bits/stdc++.h>
//\\//\\//\\//\\//\\//\\//\\//
#define fio ios::sync_with_stdio(false); cin.tie(nullptr)
#define all(x) (x).begin(),(x).end()
#define dlog(x) cerr<<#x<<'='<<x<<'\n'
#define endl '\n'
#define pb emplace_back
#define f first
#define s second
//\\//\\//\\//\\//\\//\\//\\//
using namespace::std;
using ll=long long;
using pii=pair<int,int>;
const int inf=INT_MAX,mod=1e9+7;
//\\//\\//\\//\\//\\//\\//\\//

void print(vector<int>&vec){
      for(int i=0; i<vec.size(); i++){
            cout<<vec[i]<<' ';
      }
      cout<<endl;
}

signed main(){
//      fio;
      int t; cin>>t;
      while(t--){
            int n; cin>>n;
            string str; cin>>str;
            int l=-1,r=n;
            map<pii,int>vis;
            pii cur={0,0};
            vis[cur]=0;
            for(int i=0; i<n; i++){
                  if(str[i]=='L')--cur.f;
                  if(str[i]=='R')++cur.f;
                  if(str[i]=='D')--cur.s;
                  if(str[i]=='U')++cur.s;
                  if(vis.count(cur)&&i-vis[cur]+1<r-l+1)
                        l=vis[cur],r=i;
                  vis[cur]=i+1;
            }

            if(l==-1)cout<<-1;
            else cout<<l+1<<' '<<r+1;
            cout<<endl;
      }

      return 0;
}


#include <bits/stdc++.h>
//\\//\\//\\//\\//\\//\\//\\//
#define fio ios::sync_with_stdio(false); cin.tie(nullptr)
#define all(x) (x).begin(),(x).end()
#define dlog(x) cerr<<#x<<'='<<x<<'\n'
#define endl '\n'
#define pb emplace_back
#define f first
#define s second
//\\//\\//\\//\\//\\//\\//\\//
using namespace::std;
using ll=long long;
using pii=pair<int,int>;
const int inf=INT_MAX,mod=1e9+7;
//\\//\\//\\//\\//\\//\\//\\//

void print(vector<int>&vec){
      for(int i=0; i<vec.size(); i++){
            cout<<vec[i]<<' ';
      }
      cout<<endl;
}

signed main(){
      fio;
      int t; cin>>t;
      while(t--){
            int n; cin>>n;
            string str; cin>>str;
            vector<int>vec(n);
            const int x=99;
            for(int i=0; i<n; i++){
                  if(str[i]=='L')vec[i]=1;
                  if(str[i]=='R')vec[i]=-1;
                  if(str[i]=='U')vec[i]=x;
                  if(str[i]=='D')vec[i]=-x;
            }

            vector<ll>ps(n);
            ps[0]=vec[0];
            map<int,int>have;
            int a=0,b=inf;
            for(int i=1; i<n; i++){
                  ps[i]=ps[i-1]+vec[i];
                  if(ps[i]==0) a=0,b=i;
                  if(have[ps[i]]){
                        if(b-a>i-have[ps[i]])a=have[ps[i]]+1,b=i;
                  }
                  have[ps[i]]=i;
            }

//

            if(b==inf)cout<<-1<<endl;
            else cout<<a+1<<' '<<b+1<<endl;
      }

      return 0;
}


#include <bits/stdc++.h>
//\\//\\//\\//\\//\\//\\//\\//
#define fio ios::sync_with_stdio(false); cin.tie(nullptr)
#define all(x) (x).begin(),(x).end()
#define dlog(x) cerr<<#x<<'='<<x<<'\n'
#define endl '\n'
#define pb emplace_back
#define f first
#define s second
//\\//\\//\\//\\//\\//\\//\\//
using namespace::std;
using ll=long long;
using pii=pair<int,int>;
const int inf=INT_MAX,mod=1e9+7;
//\\//\\//\\//\\//\\//\\//\\//

void print(vector<int>&vec){
      for(int i=0; i<vec.size(); i++){
            cout<<vec[i]<<' ';
      }
      cout<<endl;
}

signed main(){
      fio;
      int t; cin>>t;
      while(t--){
            int n; cin>>n;
            string str; cin>>str;
            vector<int>vec(n);
            for(int i=0; i<n; i++){
                  if(str[i]=='L')vec[i]=2;
                  if(str[i]=='R')vec[i]=-2;
                  if(str[i]=='U')vec[i]=3;
                  if(str[i]=='D')vec[i]=-3;
            }

            vector<ll>ps(n);
            ps[0]=vec[0];
            map<int,int>have;
            int a=0,b=inf;
            for(int i=1; i<n; i++){
                  ps[i]=ps[i-1]+vec[i];
                  if(ps[i]==0) a=0,b=i;
                  if(have[ps[i]]){
                        if(b-a>i-have[ps[i]])a=have[ps[i]]+1,b=i;
                  }
                  have[ps[i]]=i;
            }

//

            if(b==inf)cout<<-1<<endl;
            else cout<<a+1<<' '<<b+1<<endl;
      }

      return 0;
}


#include <bits/stdc++.h>
//\\//\\//\\//\\//\\//\\//\\//
#define fio ios::sync_with_stdio(false); cin.tie(nullptr)
#define all(x) (x).begin(),(x).end()
#define dlog(x) cerr<<#x<<'='<<x<<'\n'
#define endl '\n'
#define pb emplace_back
#define f first
#define s second
//\\//\\//\\//\\//\\//\\//\\//
using namespace::std;
using ll=long long;
using pii=pair<int,int>;
const int inf=INT_MAX,mod=1e9+7;
//\\//\\//\\//\\//\\//\\//\\//

void print(vector<int>&vec){
      for(int i=0; i<vec.size(); i++){
            cout<<vec[i]<<' ';
      }
      cout<<endl;
}

signed main(){
//      fio;
      int t; cin>>t;
      while(t--){
            int n; cin>>n;
            string str; cin>>str;
            vector<int>vec(n);
            for(int i=0; i<n; i++){
                  if(str[i]=='L')vec[i]=2;
                  if(str[i]=='R')vec[i]=-2;
                  if(str[i]=='U')vec[i]=3;
                  if(str[i]=='D')vec[i]=-3;
            }

            vector<int>ps(n);
            ps[0]=vec[0];
            map<int,int>have;
            have[ps[0]]=0;
            set<int>sim;
            sim.insert(ps[0]);
            int a=0,b=inf;
            for(int i=1; i<n; i++){
                  ps[i]=ps[i-1]+vec[i];
                  if(ps[i]==0)  if(b-a>i)a=0,b=i;
                  if(sim.count(ps[i])){
                        if(b-a>i-have[ps[i]])a=have[ps[i]]+1,b=i;
                  }
                  have[ps[i]]=i;
                  sim.insert(ps[i]);
            }

//
            if(b==inf)cout<<-1<<endl;
            else cout<<a+1<<' '<<b+1<<endl;
      }

      return 0;
}


#include <bits/stdc++.h>
//\\//\\//\\//\\//\\//\\//\\//
#define fio ios::sync_with_stdio(false); cin.tie(nullptr)
#define all(x) (x).begin(),(x).end()
#define dlog(x) cerr<<#x<<'='<<x<<'\n'
#define endl '\n'
#define pb emplace_back
#define f first
#define s second
//\\//\\//\\//\\//\\//\\//\\//
using namespace::std;
using ll=long long;
using pii=pair<int,int>;
const int inf=INT_MAX,mod=1e9+7;
//\\//\\//\\//\\//\\//\\//\\//

void print(vector<int>&vec){
      for(int i=0; i<vec.size(); i++){
            cout<<vec[i]<<' ';
      }
      cout<<endl;
}

signed main(){
      fio;
      int t; cin>>t;
      while(t--){
            int n; cin>>n;
            string str; cin>>str;
            vector<int>vec(n);
            const int x=99999;
            for(int i=0; i<n; i++){
                  if(str[i]=='L')vec[i]=1;
                  if(str[i]=='R')vec[i]=-1;
                  if(str[i]=='U')vec[i]=x;
                  if(str[i]=='D')vec[i]=-x;
            }

            vector<ll>ps(n);
            ps[0]=vec[0];
            map<int,int>have;
            int a=0,b=inf;
            for(int i=1; i<n; i++){
                  ps[i]=ps[i-1]+vec[i];
                  if(ps[i]==0) a=0,b=i;
                  if(have[ps[i]]){
                        if(b-a>i-have[ps[i]])a=have[ps[i]]+1,b=i;
                  }
                  have[ps[i]]=i;
            }

//

            if(b==inf)cout<<-1<<endl;
            else cout<<a+1<<' '<<b+1<<endl;
      }

      return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long GCD_(long long a, long long b) {
    return b ? GCD_(b, a % b) : a;
}
int main()
{
    int t; cin>>t;
    while(t--){
        int n; cin>>n;
        string s; cin>>s;
        int ans = -1;
        int st,en;
        map<pair<int,int>, int>mp;
        int x = 0 , y = 0;
        for(int i=0;i<n;i++){
            if(s[i] =='L') x--;
            else if(s[i] =='R') x++;
            else if(s[i] =='U') y++;
            else y--;
            /*founded before */
            if(mp[make_pair(x,y)] || mp[make_pair(x,y)] == 1e6){
                if(ans == -1){
                    ans = i - mp[make_pair(x,y)] + 1;
                    st = mp[make_pair(x,y)] + 1;
                    en = i+1;
                    mp[make_pair(x,y)] = i;
                }
                else{
                    if(mp[make_pair(x,y)] == 1e6) mp[make_pair(x,y)] = 0;
                    if(ans > i - mp[make_pair(x,y)] + 1){
                        ans = i - mp[make_pair(x,y)] + 1;
                        st = mp[make_pair(x,y)] + 1;
                        en = i+1;
                        mp[make_pair(x,y)] = i;
                    }
                }
            }
            /*Not founded */
            else
               mp[make_pair(x,y)] = i;
        }
        if(ans == - 1) {
            int arr[4] = {0};
            bool is = false;
            for(int i = 0 ; i<n;i++){
                if(s[i] =='L') arr[0]++;
                else if(s[i] =='R') arr[1]++;
                else if(s[i] =='U') arr[2]++;
                else arr[3]++;
                   if(arr[0] == arr[1] && arr[2] == arr[3]){
                   cout<<1<<" "<<i+1<<endl;
                   is = true;
                   break;
                }
            }
             if(!is)cout<<-1<<endl;
        }
        else cout<<st+1<<" "<<en<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long GCD_(long long a, long long b) {
    return b ? GCD_(b, a % b) : a;
}
int main()
{
    int t; cin>>t;
    while(t--){
        int n; cin>>n;
        string s; cin>>s;
        int ans = -1;
        int st,en;
        map<pair<int,int>, int>mp;
        int x = 0 , y = 0;
        for(int i=0;i<n;i++){
            if(s[i] =='L') x--;
            else if(s[i] =='R') x++;
            else if(s[i] =='U') y++;
            else y--;
            /*founded before */
            if(mp[make_pair(x,y)] || mp[make_pair(x,y)] == 1e6){
                if(ans == -1){
                    ans = i - mp[make_pair(x,y)] + 1;
                    st = mp[make_pair(x,y)] + 1;
                    en = i+1;
                    if(mp[make_pair(x,y)] == 1e6){
                        ans -= 1e6;
                        st -= 1e6;
                    }
                    mp[make_pair(x,y)] = i;
                }
                else{
                    if(mp[make_pair(x,y)] == 1e6) mp[make_pair(x,y)] = 0;
                    if(ans > i - mp[make_pair(x,y)] + 1){
                        ans = i - mp[make_pair(x,y)] + 1;
                        st = mp[make_pair(x,y)] + 1;
                        en = i+1;
                        mp[make_pair(x,y)] = i;
                    }
                }
            }
            /*Not founded */
            else
                if(i == 0)
                mp[make_pair(x,y)] = 1e6;
                else
               mp[make_pair(x,y)] = i;
        }
        if(ans == - 1) {
            int arr[4] = {0};
            for(int i = 0 ; i<n;i++)
                if(s[i] =='L') arr[0]++;
                else if(s[i] =='R') arr[1]++;
                else if(s[i] =='U') arr[2]++;
                else arr[3]++;
            if(arr[0] == arr[1] && arr[2] == arr[3])
                cout<<1<<" "<<n<<endl;
            else
            cout<<ans<<endl;
        }
        else cout<<st+1<<" "<<en<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long GCD_(long long a, long long b) {
    return b ? GCD_(b, a % b) : a;
}
int dp[200505][2][2][2][2];
int n;
string s;
int t;
int solve(int i,int l,int r,int u,int d){
       if(i == n+1)return dp[i][l][r][u][d] = 1e8;
   if(dp[i][l][r][u][d] != -1) return dp[i][l][r][u][d];
   if( l == r && u == d && l+r+u+d != 0) return dp[i][l][r][u][d] = l+r+u+d;
   else {
    int a = solve(i+1,0,0,0,0);
    int b;
    if(s[i] == 'L') b = solve(i+1,l+1,r,u,d);
    else if (s[i] == 'R') b = solve(i+1,l,r+1,u,d);
    else if(s[i] == 'U') b = solve(i+1,l,r,u+1,d);
    else  b = solve(i+1,l,r,u,d+1);
    return dp[i][l][r][u][d] = min(a,b);
   }
}
int main()
{
    cin>>t;
    while(t--){
        cin>>n;
        memset(dp,-1,n+500);
        cin>>s;
        s+="Y";
        int ans = solve(0,0,0,0,0);
        if(ans == 1e8) cout<<-1<<endl;
        else {
        int l = 0, r = 0 , u = 0 , d = 0;
        for(int i=0;i<ans;i++)
            if(s[i] == 'L') l++;
            else if(s[i] =='R')r++;
            else if(s[i] =='U')u++;
            else d++;
        for(int i=ans;i<n+1;i++){
            if(l == r && u == d){ cout<<i-ans+1<<" "<<i<<endl; break; }
            if(s[i-ans] == 'L') l--;
             else if(s[i-ans] =='R')r--;
              else if(s[i-ans] =='U')u--;
             else d--;
            /* */
             if(s[i] == 'L') l++;
             else if(s[i] =='R')r++;
              else if(s[i] =='U')u++;
             else d++;
             //cout<<l<<" "<<r<<" "<<u<<" "<<d<<endl;
            /* */
          }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long GCD_(long long a, long long b) {
    return b ? GCD_(b, a % b) : a;
}
int main()
{
    int t; cin>>t;
    while(t--){
        int n; cin>>n;
        string s; cin>>s;
        int x = 0, y = 0;
        int ans = 1e6;
        int st,en;
        map<pair<int,int>, int> mp;
        mp[{0,0}] = 1;
        bool f = false;
        for(int i=0;i<n;i++){
            if(s[i] == 'L') x--;
            else if(s[i] =='R') x++;
            else if(s[i] =='U')y++;
            else y--;
            if(mp[{x,y}]){
                if(ans > i - mp[{x,y}] + 1){
                    ans = i - mp[{x,y}] + 1;
                    st = mp[{x,y}];
                    en = i+1;
                    if(x==0&&y==0&&!f){ st--; f = true; }
                }
                mp[{x,y}] = i+1;
            }
            else{
                mp[{x,y}] = i+1;
            }
        }
        if(ans == 1e6) cout<<-1<<endl;
        else cout<<st+1<<" "<<en<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long GCD_(long long a, long long b) {
    return b ? GCD_(b, a % b) : a;
}
int main()
{
    int t; cin>>t;
    while(t--){
        int n; cin>>n;
        string s; cin>>s;
        int ans = -1;
        int st,en;
        map<pair<int,int>, int>mp;
        int x = 0 , y = 0;
        for(int i=0;i<n;i++){
            if(s[i] =='L') x--;
            else if(s[i] =='R') x++;
            else if(s[i] =='U') y++;
            else y--;
            /*founded before */
            if(mp[make_pair(x,y)]){
                if(ans == -1){
                    ans = i - mp[make_pair(x,y)];
                    st = mp[make_pair(x,y)];
                    en = i+1;
                    mp[make_pair(x,y)] = i;
                }
                else{
                    if(ans > i - mp[make_pair(x,y)] ){
                        ans = i - mp[make_pair(x,y)] ;
                        st = mp[make_pair(x,y)] ;
                        en = i+1;
                        mp[make_pair(x,y)] = i+1;
                    }
                }
            }
            /*Not founded */
            else
               mp[make_pair(x,y)] = i+1;
        }
        if(ans == - 1) {
            int arr[4] = {0};
            bool is = false;
            for(int i = 0 ; i<n;i++){
                if(s[i] =='L') arr[0]++;
                else if(s[i] =='R') arr[1]++;
                else if(s[i] =='U') arr[2]++;
                else arr[3]++;
                   if(arr[0] == arr[1] && arr[2] == arr[3]){
                   cout<<1<<" "<<i+1<<endl;
                   is = true;
                   break;
                }
            }
             if(!is)cout<<-1<<endl;
        }
        else cout<<st+1<<" "<<en<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long GCD_(long long a, long long b) {
    return b ? GCD_(b, a % b) : a;
}
int main()
{
    int t; cin>>t;
    while(t--){
        int n; cin>>n;
        string s; cin>>s;
        int ans = -1;
        int st,en;
        map<pair<int,int>, int>mp;
        int x = 0 , y = 0;
        for(int i=0;i<n;i++){
            if(s[i] =='L') x--;
            else if(s[i] =='R') x++;
            else if(s[i] =='U') y++;
            else y--;
            /*founded before */
            if(mp[make_pair(x,y)] || mp[make_pair(x,y)] == 1e6){
                if(ans == -1){
                    ans = i - mp[make_pair(x,y)] + 1;
                    st = mp[make_pair(x,y)] + 1;
                    en = i+1;
                    mp[make_pair(x,y)] = i;
                }
                else{
                    if(mp[make_pair(x,y)] == 1e6) mp[make_pair(x,y)] = 0;
                    if(ans > i - mp[make_pair(x,y)] + 1){
                        ans = i - mp[make_pair(x,y)] + 1;
                        st = mp[make_pair(x,y)] + 1;
                        en = i+1;
                        mp[make_pair(x,y)] = i;
                    }
                }
            }
            /*Not founded */
            else
               mp[make_pair(x,y)] = i;
        }
        if(ans == - 1) {
            int arr[4] = {0};
            for(int i = 0 ; i<n;i++)
                if(s[i] =='L') arr[0]++;
                else if(s[i] =='R') arr[1]++;
                else if(s[i] =='U') arr[2]++;
                else arr[3]++;
            if(arr[0] == arr[1] && arr[2] == arr[3])
                cout<<1<<" "<<n<<endl;
            else
            cout<<ans<<endl;
        }
        else cout<<st+1<<" "<<en<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long GCD_(long long a, long long b) {
    return b ? GCD_(b, a % b) : a;
}
int main()
{
    int t; cin>>t;
    while(t--){
        int n; cin>>n;
        string s; cin>>s;
        int x = 0, y = 0;
        int ans = 1e6;
        int st,en;
        map<pair<int,int>, int> mp;
        mp[{0,0}] = 1;
        for(int i=1;i<=n;i++){
            if(s[i-1] == 'L') x--;
            else if(s[i-1] =='R') x++;
            else if(s[i-1] =='U')y++;
            else y--;
            if(mp[{x,y}]){
                if(ans > i - mp[{x,y}] + 1){
                    ans = i - mp[{x,y}] + 1;
                    st = mp[{x,y}];
                    en = i;
                }
                mp[{x,y}] = i+1;
            }
            else{
                mp[{x,y}] = i+1;
            }
        }
        if(ans == 1e6) cout<<-1<<endl;
        else cout<<st<<" "<<en<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long GCD_(long long a, long long b) {
    return b ? GCD_(b, a % b) : a;
}
int main()
{
    int t; cin>>t;
    while(t--){
        int n; cin>>n;
        string s; cin>>s;
        int ans = -1;
        int st,en;
        map<pair<int,int>, int>mp;
        int x = 0 , y = 0;
        for(int i=0;i<n;i++){
            if(s[i] =='L') x--;
            else if(s[i] =='R') x++;
            else if(s[i] =='U') y++;
            else y--;
            /*founded before */
            if(mp[make_pair(x,y)]){
                if(ans == -1){
                    ans = i - mp[make_pair(x,y)];
                    st = mp[make_pair(x,y)];
                    en = i+1;
                    mp[make_pair(x,y)] = i+1;
                }
                else{
                    if(ans > i - mp[make_pair(x,y)] ){
                        ans = i - mp[make_pair(x,y)] ;
                        st = mp[make_pair(x,y)] ;
                        en = i+1;
                        mp[make_pair(x,y)] = i+1;
                    }
                }
            }
            /*Not founded */
            else
               mp[make_pair(x,y)] = i+1;
        }
        if(ans == - 1) {
            int arr[4] = {0};
            bool is = false;
            for(int i = 0 ; i<n;i++){
                if(s[i] =='L') arr[0]++;
                else if(s[i] =='R') arr[1]++;
                else if(s[i] =='U') arr[2]++;
                else arr[3]++;
                   if(arr[0] == arr[1] && arr[2] == arr[3]){
                   cout<<1<<" "<<i+1<<endl;
                   is = true;
                   break;
                }
            }
             if(!is)cout<<-1<<endl;
        }
        else cout<<st+1<<" "<<en<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long GCD_(long long a, long long b) {
    return b ? GCD_(b, a % b) : a;
}
int dp[200005][2][2][2][2];
int n;
string s;
int solve(int i,int l,int r,int u,int d){
   if(dp[i][l][r][u][d] != -1) return dp[i][l][r][u][d];
   if(i == n+1)return dp[i][l][r][u][d] = 1e8;
   if( l == r && u == d && l+r+u+d != 0) return dp[i][l][r][u][d] = l+r+u+d;
   else {
    int a = solve(i+1,0,0,0,0);
    int b;
    if(s[i] == 'L') b = solve(i+1,l+1,r,u,d);
    else if (s[i] == 'R') b = solve(i+1,l,r+1,u,d);
    else if(s[i] == 'U') b = solve(i+1,l,r,u+1,d);
    else  b = solve(i+1,l,r,u,d+1);
    return dp[i][l][r][u][d] = min(a,b);
   }
}
int main()
{
    int t; cin>>t;
    while(t--){
        memset(dp,-1,sizeof(dp));
        cin>>n;
        cin>>s;
        s+="Y";
        int ans = solve(0,0,0,0,0);
        if(ans == 1e8) cout<<-1<<endl;
        else {
        int l = 0, r = 0 , u = 0 , d = 0;
        for(int i=0;i<ans;i++)
            if(s[i] == 'L') l++;
            else if(s[i] =='R')r++;
            else if(s[i] =='U')u++;
            else d++;
        for(int i=ans;i<n+1;i++){
            if(l == r && u == d){ cout<<i-ans+1<<" "<<i<<endl; break; }
            if(s[i-ans] == 'L') l--;
             else if(s[i-ans] =='R')r--;
              else if(s[i-ans] =='U')u--;
             else d--;
            /* */
             if(s[i] == 'L') l++;
             else if(s[i] =='R')r++;
              else if(s[i] =='U')u++;
             else d++;
             //cout<<l<<" "<<r<<" "<<u<<" "<<d<<endl;
            /* */
          }
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
int n,q,l[100001],r[100001],s[100001],ans;
int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>s[i];
    cin>>q;
    for(int i=1;i<=q;i++)
        cin>>l[i]>>r[i];
    for(int i=1;i<=q;i++){
        int sum=0;
        for(int j=l[i];j<=r[i];j++){
            sum+=s[j];
        }
        ans=sum/10;
        cout<<ans<<" ";
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>

#define LS (now << 1)
#define RS (now << 1 | 1)

using namespace std;

typedef long long LL;

const int MAX_N = 1e5 + 5;
const int INF = 0x3f3f3f3f;

int n, s[MAX_N], q, f[MAX_N][20], cnt[MAX_N][20], lg[MAX_N];

void init() {
	lg[1] = 0;
	for (int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;
	for (int i = 1; i <= n; i++) f[i][0] = s[i];
	for (int i = 1; 1 << i <= n; i++) {
		for (int j = 1; j + (1 << i) - 1 <= n; j++) {
			int sum = f[j][i - 1] + f[j + (1 << i - 1)][i - 1];
			f[j][i] = sum % 10;
			cnt[j][i] = cnt[j][i - 1] + cnt[j + (1 << i - 1)][i - 1] + (sum >= 10);
		}
	}
}

void solve() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", s + i);
	init();
	scanf("%d", &q);
	while (q--) {
		int L, R;
		scanf("%d%d", &L, &R);
		int len = lg[R - L + 1];
		printf("%d\n", cnt[L][len]);
	}
}

int main() {
	//ios::sync_with_stdio(false);
	//freopen("in.txt", "r", stdin);
	solve();
	return 0;
}


#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
const int maxn=1e5+5;
int s[maxn];
int main()
{
	int n,i;
	cin>>n;
	for (i=1;i<=n;i++){
		scanf("%d",&s[i]);
	}
	int qr,l,r;
	cin>>qr;
	while(qr--){
		scanf("%d%d",&l,&r);
		queue<int> q;
		for (i=l;i<=r;i++){
			q.push(s[i]);
			//cout<<s[i]<<" ";
		}
		int tot=0;
		while(q.size()>1){
			int a=q.front();q.pop();
			int b=q.front();q.pop();
			q.push((a+b)%10);
			if (a+b>=10) tot++;
		}
		printf("%d\n",tot);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;

vector< vector< pair<int,int> > > dp(20);
int main()
{
	int n;
	cin>>n;
	vector<int> num(n);
	for(int i=0;i<n;i++){
		cin>>num[i];
		dp[0].push_back(make_pair(num[i],0));
	}

	int len=n;
	for(int deg=1;deg<20;deg++){
		for(int i=0;i<len-1;i+=2){
			int left1=dp[deg-1][i].first;
			int left2=dp[deg-1][i+1].first;
			int candy1=dp[deg-1][i].second;
			int candy2=dp[deg-1][i+1].second;
			int sum=left1+left2;
			int candy=candy1+candy2;
			if(sum>=10)candy++;
			sum%=10;
			dp[deg].push_back(make_pair(sum,candy));
		}
	//	cout<<dp[deg].size()<<endl;
		len/=2;
	}
//	cout<<dp.size()<<endl;
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		int l,r;
		cin>>l>>r;
		int len=r-l+1,k=0;

		l--;
		while(len%2==0){
			len/=2;
			k++;
			l/=2;
		}

		//cout<<k<<" :"<<dp[k][l].second<<" "<<endl;
		cout<<dp[k][l].second<<" ";
	}
	return 0;
 }


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MAXN 100010
int a[MAXN],n,cnt,m,q,l,r,c[MAXN];
template<typename T>
inline void read(T& x){
    x=0;
    int f(1);
    char ch(getchar());
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
    x=f*x;
}
int main(){
    read(n);
    for(register int i(1);i<=n;++i) {read(a[i]);c[i]=c[i-1]+a[i];}
    read(q);
    while(q--){
        read(l);read(r);
        int sum=c[r]-c[l-1];
        cout<<sum/10<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+5;
int num[MAXN],put[MAXN];
int l[MAXN],r[MAXN];

int main()
{
	int n,q;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>num[i];
	}
	cin>>q;
	for(int i=0;i<q;i++)
	{
		cin>>l[i]>>r[i];
	}
	for(int i=0;i<q;i++)
	{
		int ans =0,len1 =abs(r[i]-l[i])+1;
		if(len1>1)
		{
			int len2 =0;
			for(int j = l[i];j<=r[i];j+=2)
			{
				ans+=(num[j]+num[j+1])/10;
				put[len2++] = (num[j]+num[j+1])%10;
			}
			while(len2>1)
			{
				len1 = len2;
				len2 =0;
				for(int  j=0;j<len1;j+=2)
				{
					ans+=(put[j]+put[j+1])/10;
					put[len2++] = (put[j]+put[j+1])%10;
				}
			}
		}
		if(i<q-1)
		cout<<ans<<" ";
		else
		cout<<ans<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;

vector< vector< pair<int,int> > > dp(20);
int main()
{
	int n;
	cin>>n;
	vector<int> num(n);
	for(int i=0;i<n;i++){
		cin>>num[i];
		dp[0].push_back(make_pair(num[i],0));
	}

	//int len=n;
	int cur=1;
	for(int deg=1;deg<20;deg++){
		cur*=2;
		for(int i=0;i<=n-cur;i++){
			int left1=dp[deg-1][i].first;
			int left2=dp[deg-1][i+cur/2].first;
			int candy1=dp[deg-1][i].second;
			int candy2=dp[deg-1][i+cur/2].second;
			int sum=left1+left2;
			int candy=candy1+candy2;
			if(sum>=10)candy++;
			sum%=10;
			dp[deg].push_back(make_pair(sum,candy));
		}
		//cout<<dp[deg].size()<<endl;
		//len/=2;
	}
//	cout<<dp.size()<<endl;
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		int l,r;
		cin>>l>>r;
		int len=r-l+1,k=0;

		//l--;
		while(len%2==0){
			len/=2;
			k++;
		//	l/=2;
		}

		//cout<<k<<" :"<<dp[k][l].second<<" "<<endl;
		cout<<dp[k][l-1].second<<" ";
	}
	return 0;
 }


#include<iostream>
using namespace std;
int n,q,l[10001],r[10001],s[100001],ans;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>s[i];
    cin>>q;
    for(int i=1;i<=q;i++)
        cin>>l[i]>>r[i];
    for(int i=1;i<=q;i++){
        int sum=0;
        for(int j=l[i];j<=r[i];j++){
            sum+=s[j];
        }
        ans=sum/10;
        cout<<ans<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int max_n=100005;

int a[max_n];
pair <int,int> s[max_n];
long long f[max_n];
int n,m;

int main()
{
    int i;
    cin >> n;
    for (i=0;i<n;i++)
        cin >>a[i];
    cin >> m;
    for(i=0;i<m;i++)
        cin >> s[i].first >> s[i].second;
    f[0]=0;
    for (i=1;i<=n;i++)
        f[i]=f[i-1]+a[i-1];
    for (i=0;i<m;i++)
    {
        cout <<(f[s[i].second]-f[s[i].first-1])/10<<' ';
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<map>
using namespace std;
#define scan(n) scanf("%d",&n)
#define ll long long

int a[100005];
int s[100005];

int main()
{
    int n,q,i;
    scan(n);
    for(i=1;i<=n;i++)
        scan(a[i]);
    s[0]=0;
    s[1]=a[1];
    for(i=2;i<=n;i++)
        s[i]=s[i-1]+a[i];
    scan(q);
    int l,r;
    while(q--)
    {
        scan(l);
        scan(r);
        cout<<(s[r]-s[l-1])/10<<endl;
    }
    return 0;
}


/*
题意
给出一个数字序列，
在指定的区间内
每两个数字进行合并
如果两个数字之和大于等于10
则糖果数加一，
然后取和的结果mod 10作为合并结果

重复进行合并操作直到不能合并
求最终的糖果数

思路
动态规划，
使用结构体pair保存
合并后的值与合并后得到的糖果数

dp[i]保存合并i次后所有区间内的解
dp[0]={ <,0>, <,0> ... <,0> }
合并0次时所有区间的糖果数都为0

dp[i]= 合并 j 与 j+2^(i-1) 的pair
			 for j in 0..n-2^(i-1)
*/

#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;

vector< vector< pair<int,int> > > dp(20);
int main()
{
	int n;
	cin>>n;
	vector<int> num(n);
	for(int i=0;i<n;i++){
		cin>>num[i];
		dp[0].push_back(make_pair(num[i],0));
	}

	//int len=n;
	int cur=1;
	for(int deg=1;deg<20;deg++){
		cur*=2;
		for(int i=0;i<=n-cur;i++){
			int left1=dp[deg-1][i].first;
			int left2=dp[deg-1][i+cur/2].first;
			int candy1=dp[deg-1][i].second;
			int candy2=dp[deg-1][i+cur/2].second;
			int sum=left1+left2;
			int candy=candy1+candy2;
			if(sum>=10)candy++;
			sum%=10;
			dp[deg].push_back(make_pair(sum,candy));
		}
		cout<<dp[deg].size()<<endl;
		//len/=2;
	}
//	cout<<dp.size()<<endl;
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		int l,r;
		cin>>l>>r;
		int len=r-l+1,k=0;

		//l--;
		while(len%2==0){
			len/=2;
			k++;
		//	l/=2;
		}

		//cout<<k<<" :"<<dp[k][l].second<<" "<<endl;
		cout<<dp[k][l-1].second<<" ";
	}
	return 0;
 }


%:pragma GCC optimize(2)
%:pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define lll __int128
#define dd double
#define _i int
#define RE register
#define rep(i, l, r) for (RE int i = l; i <= r; i++)
#define req(i, l, r) for (RE int i = l; i >= r; i--)
#define range(i, l, r) rep(i, l, r - 1)
#define Be(s, t) memset(s, t, sizeof(s))
#define poly vector <int>
#define pii pair <int, int>
template <typename T> void read(T &x) { x = 0; int FF = 1; char op = getchar(); while (!isdigit(op)) { if (op == '-') FF = -1; op = getchar(); } while (isdigit(op)) { x = (x << 1) + (x << 3) + op - '0'; op = getchar(); } x *= FF; }
template <typename T> void print(T x) { if (x < 0) { putchar('-'); x = -x; } if (x < 1) return ; print(x / 10); putchar(x % 10 + '0'); }
template <typename T> void print(T x, char _tab) { print(x); putchar(_tab); }

const int maxn = 100005;
int a[maxn], b[maxn], sum[maxn];
long long dp[maxn][25];
int n;

void pre() {
  for (int i = 1; i <= n; i++)
    dp[i][0] = 0;
  for (int k = 1; k <= 20; k++) {
    for (int i = 1; i + (1 << k) - 1 <= n; i++) {
      dp[i][k] = dp[i][k - 1] + dp[i + (1 << (k - 1))][k - 1];
      int v1 = sum[i + (1 << (k - 1)) - 1] - sum[i - 1]; v1 %= 10;
      int v2 = sum[i + (1 << k) - 1] - sum[i + (1 << (k - 1)) - 1]; v2 %= 10;
      if (v1 + v2 >= 10) dp[i][k]++;
    }
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  pre();
  int q; scanf("%d", &q);
  while (q--) {
    int l, r; scanf("%d%d", &l, &r);
    int Log = (int)log2(r - l + 1);
    printf("%lld\n", dp[l][Log]);
  }
  return 0;
}
// zhouzhuan, 233


%:pragma GCC optimize(2)
%:pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define lll __int128
#define dd double
#define _i int
#define RE register
#define rep(i, l, r) for (RE int i = l; i <= r; i++)
#define req(i, l, r) for (RE int i = l; i >= r; i--)
#define range(i, l, r) rep(i, l, r - 1)
#define Be(s, t) memset(s, t, sizeof(s))
#define poly vector <int>
#define pii pair <int, int>
template <typename T> void read(T &x) { x = 0; int FF = 1; char op = getchar(); while (!isdigit(op)) { if (op == '-') FF = -1; op = getchar(); } while (isdigit(op)) { x = (x << 1) + (x << 3) + op - '0'; op = getchar(); } x *= FF; }
template <typename T> void print(T x) { if (x < 0) { putchar('-'); x = -x; } if (x < 1) return ; print(x / 10); putchar(x % 10 + '0'); }
template <typename T> void print(T x, char _tab) { print(x); putchar(_tab); }

const int maxn = 100005;
int a[maxn], b[maxn], sum[maxn];
int dp[maxn][20];
int n;

void pre() {
  for (int i = 1; i <= n; i++)
    dp[i][0] = 0;
  for (int k = 1; k <= 15; k++) {
    for (int i = 1; i + (1 << k) - 1 <= n; i++) {
      dp[i][k] = dp[i][k - 1] + dp[i + (1 << (k - 1))][k - 1];
      int v1 = sum[i + (1 << (k - 1)) - 1] - sum[i - 1]; v1 %= 10;
      int v2 = sum[i + (1 << k) - 1] - sum[i + (1 << (k - 1)) - 1]; v2 %= 10;
      if (v1 + v2 >= 10) dp[i][k]++;
    }
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  pre();
  int q; scanf("%d", &q);
  while (q--) {
    int l, r; scanf("%d%d", &l, &r);
    int Log = (int)(log((double)(r - l + 1)) / log(2));
    printf("%d\n", dp[l][Log]);
  }
  return 0;
}


%:pragma GCC optimize(2)
%:pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define lll __int128
#define dd double
#define _i int
#define RE register
#define rep(i, l, r) for (RE int i = l; i <= r; i++)
#define req(i, l, r) for (RE int i = l; i >= r; i--)
#define range(i, l, r) rep(i, l, r - 1)
#define Be(s, t) memset(s, t, sizeof(s))
#define poly vector <int>
#define pii pair <int, int>
template <typename T> void read(T &x) { x = 0; int FF = 1; char op = getchar(); while (!isdigit(op)) { if (op == '-') FF = -1; op = getchar(); } while (isdigit(op)) { x = (x << 1) + (x << 3) + op - '0'; op = getchar(); } x *= FF; }
template <typename T> void print(T x) { if (x < 0) { putchar('-'); x = -x; } if (x < 1) return ; print(x / 10); putchar(x % 10 + '0'); }
template <typename T> void print(T x, char _tab) { print(x); putchar(_tab); }

const int maxn = 100005;
int a[maxn], b[maxn], sum[maxn];
int dp[maxn][25];
int n;

void pre() {
  for (int i = 1; i <= n; i++)
    dp[i][0] = 0;
  for (int k = 1; k <= 20; k++) {
    for (int i = 1; i + (1 << k) - 1 <= n; i++) {
      dp[i][k] = dp[i][k - 1] + dp[i + (1 << (k - 1))][k - 1];
      int v1 = sum[i + (1 << (k - 1)) - 1] - sum[i - 1]; v1 %= 10;
      int v2 = sum[i + (1 << k) - 1] - sum[i + (1 << (k - 1)) - 1]; v2 %= 10;
      if (v1 + v2 >= 10) dp[i][k]++;
    }
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  pre();
  int q; scanf("%d", &q);
  while (q--) {
    int l, r; scanf("%d%d", &l, &r);
    int Log = (int)(log((double)(r - l + 1)) / log(2));
    printf("%d\n", dp[l][Log]);
  }
  return 0;
}


%:pragma GCC optimize(2)
%:pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define lll __int128
#define dd double
#define _i int
#define RE register
#define rep(i, l, r) for (RE int i = l; i <= r; i++)
#define req(i, l, r) for (RE int i = l; i >= r; i--)
#define range(i, l, r) rep(i, l, r - 1)
#define Be(s, t) memset(s, t, sizeof(s))
#define poly vector <int>
#define pii pair <int, int>
template <typename T> void read(T &x) { x = 0; int FF = 1; char op = getchar(); while (!isdigit(op)) { if (op == '-') FF = -1; op = getchar(); } while (isdigit(op)) { x = (x << 1) + (x << 3) + op - '0'; op = getchar(); } x *= FF; }
template <typename T> void print(T x) { if (x < 0) { putchar('-'); x = -x; } if (x < 1) return ; print(x / 10); putchar(x % 10 + '0'); }
template <typename T> void print(T x, char _tab) { print(x); putchar(_tab); }

#define int long long
const int maxn = 100005;
int a[maxn], b[maxn], sum[maxn];
int dp[maxn][25];
int n;

void pre() {
  for (int i = 1; i <= n; i++)
    dp[i][0] = 0;
  for (int k = 1; k <= 20; k++) {
    for (int i = 1; i + (1 << k) - 1 <= n; i++) {
      dp[i][k] = dp[i][k - 1] + dp[i + (1 << (k - 1))][k - 1];
      int v1 = sum[i + (1 << (k - 1)) - 1] - sum[i - 1]; v1 %= 10;
      int v2 = sum[i + (1 << k) - 1] - sum[i + (1 << (k - 1)) - 1]; v2 %= 10;
      if (v1 + v2 >= 10) dp[i][k]++;
    }
  }
}

signed main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  pre();
  int q; scanf("%lld", &q);
  while (q--) {
    int l, r; scanf("%lld%lld", &l, &r);
    int Log = (int)log2((double)(r - l + 1));
    printf("%lld\n", dp[l][Log]);
  }
  return 0;
}


#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
using  namespace std;
typedef long long ll;
typedef unsigned long long ul;
#define sc(x) scanf("%d",&x)
#define pd(x) printf("%d\n",x)
const double eps=1e-8;
const double PI=acos(-1.0);
const int INF=0x3f3f3f3f;
const int mod=10000;
const int N=1e5+10;
struct node
{
    int l,r;
    int num,ans;
} a[N<<2];
void build(int l,int r,int k)
{
    a[k].l=l,a[k].r=r,a[k].num=a[k].ans=0;
    if(l==r)
    {
        scanf("%d",&a[k].num);
        return ;
    }
    int mid=(l+r)>>1;
    build(l,mid,2*k);
    build(mid+1,r,2*k+1);
    int tmp=a[k*2].num+a[k*2+1].num;
    if(tmp>=10)
        a[k].ans++;
    a[k].num=tmp%10;
    a[k].ans+=a[k*2].ans+a[k*2+1].ans;
}
int query(int l,int r,int k,int &cnt)
{
//    printf("l=%d r=%d %d %d %d\n",l,r,cnt,a[k].l,a[k].r);
    if(l==a[k].l&&r==a[k].r)
    {
        cnt+=a[k].ans;
        return a[k].num;
    }
    int mid=(a[k].l+a[k].r)>>1;
    if(r<=mid)
        return query(l,r,2*k,cnt)%10;
    else if(l>mid)
        return query(l,r,2*k+1,cnt)%10;
    else
    {
        int Mid=(l+r)>>1;
//        printf("----------- mid=%d  Mid=%d\n",mid,Mid);
        int tmp=0;
        if(mid<Mid)
            tmp=query(l,mid,2*k,cnt)+query(mid+1,Mid,2*k+1,cnt)+query(Mid+1,r,2*k+1,cnt);
        else if(mid==Mid)
            tmp=query(l,mid,2*k,cnt)+query(mid+1,r,2*k+1,cnt);
        else
            tmp=query(l,Mid,2*k,cnt)+query(Mid+1,mid,2*k,cnt)+query(mid+1,r,2*k+1,cnt);
        if(tmp>=10)
            cnt++;
        return tmp%10;
    }
}
int main()
{
    int n,q;
    while(~scanf("%d",&n))
    {
        build(1,n,1);
//        printf("YESSS\n");
        scanf("%d",&q);
        int l,r;
        while(q--)
        {
            scanf("%d%d",&l,&r);
            int ans=0;
            query(l,r,1,ans);
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
using  namespace std;
typedef long long ll;
typedef unsigned long long ul;
#define sc(x) scanf("%d",&x)
#define pd(x) printf("%d\n",x)
const double eps=1e-8;
const double PI=acos(-1.0);
const int INF=0x3f3f3f3f;
const int mod=10000;
const int N=1e5+10;
struct node
{
    int l,r;
    int num,ans;
} a[N<<2];
void build(int l,int r,int k)
{
    a[k].l=l,a[k].r=r,a[k].num=a[k].ans=0;
    if(l==r)
    {
        scanf("%d",&a[k].num);
        return ;
    }
    int mid=(l+r)>>1;
    build(l,mid,2*k);
    build(mid+1,r,2*k+1);
    int tmp=a[k*2].num+a[k*2+1].num;
    if(tmp>=10)
        a[k].ans++;
    a[k].num=tmp%10;
    a[k].ans+=a[k*2].ans+a[k*2+1].ans;
}
int query(int l,int r,int k,int &cnt)
{
//    printf("l=%d r=%d %d %d %d\n",l,r,cnt,a[k].l,a[k].r);
    if(l==a[k].l&&r==a[k].r)
    {
        cnt+=a[k].ans;
        return a[k].num;
    }
    int mid=(a[k].l+a[k].r)>>1;
    if(r<=mid)
        return query(l,r,2*k,cnt);
    else if(l>mid)
        return query(l,r,2*k+1,cnt);
    else
    {
        int Mid=(l+r)>>1;
//        printf("----------- mid=%d  Mid=%d\n",mid,Mid);
        int tmp=0;
        if(mid<Mid)
            tmp=query(l,mid,2*k,cnt)+query(mid+1,Mid,2*k+1,cnt)+query(Mid+1,r,2*k+1,cnt);
        else if(mid==Mid)
            tmp=query(l,mid,2*k,cnt)+query(mid+1,r,2*k+1,cnt);
        else
            tmp=query(l,Mid,2*k,cnt)+query(Mid+1,mid,2*k,cnt)+query(mid+1,r,2*k+1,cnt);
        if(tmp>=10)
            cnt++;
        return tmp%10;
    }
}
int main()
{
    int n,q;
    while(~scanf("%d",&n))
    {
        build(1,n,1);
        printf("YESSS\n");
        scanf("%d",&q);
        int l,r;
        while(q--)
        {
            scanf("%d%d",&l,&r);
            int ans=0;
            query(l,r,1,ans);
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
using  namespace std;
typedef long long ll;
typedef unsigned long long ul;
#define sc(x) scanf("%d",&x)
#define pd(x) printf("%d\n",x)
const double eps=1e-8;
const double PI=acos(-1.0);
const int INF=0x3f3f3f3f;
const int mod=10000;
const int N=1e5+10;
int a[N];
int main()
{
    int n,q;
    cin>>n;
    a[0]=0;
    for(int i=1;i<=n;i++)
    {cin>>a[i];a[i]+=a[i-1];}
    cin>>q;
    while(q--)
    {
        int l,r;
        cin>>l>>r;
        cout<<(a[r]-a[l-1])/10<<endl;
    }
}


#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
using  namespace std;
typedef long long ll;
typedef unsigned long long ul;
#define sc(x) scanf("%d",&x)
#define pd(x) printf("%d\n",x)
const double eps=1e-8;
const double PI=acos(-1.0);
const int INF=0x3f3f3f3f;
const int mod=10000;
const int N=1e5+10;
struct node
{
    int l,r;
    int num,ans;
} a[N<<2];
void build(int l,int r,int k)
{
    a[k].l=l,a[k].r=r,a[k].num=a[k].ans=0;
    if(l==r)
    {
        scanf("%d",&a[k].num);
        return ;
    }
    int mid=(l+r)>>1;
    build(l,mid,2*k);
    build(mid+1,r,2*k+1);
    int tmp=a[k*2].num+a[k*2+1].num;
    if(tmp>=10)
        a[k].ans++;
    a[k].num=tmp%10;
    a[k].ans+=a[k*2].ans+a[k*2+1].ans;
}
int query(int l,int r,int k,int &cnt)
{
//    printf("l=%d r=%d %d %d %d\n",l,r,cnt,a[k].l,a[k].r);
    if(l==a[k].l&&r==a[k].r)
    {
        cnt+=a[k].ans;
        return a[k].num;
    }
    int mid=(a[k].l+a[k].r)>>1;
    if(r<=mid)
        return query(l,r,2*k,cnt);
    else if(l>mid)
        return query(l,r,2*k+1,cnt);
    else
    {
        int Mid=(l+r)>>1;
//        printf("----------- mid=%d  Mid=%d\n",mid,Mid);
        int tmp=0;
        if(mid<Mid)
            tmp=query(l,mid,2*k,cnt)+query(mid+1,Mid,2*k+1,cnt)+query(Mid+1,r,2*k+1,cnt);
        else if(mid==Mid)
            tmp=query(l,mid,2*k,cnt)+query(mid+1,r,2*k+1,cnt);
        else
            tmp=query(l,Mid,2*k,cnt)+query(Mid+1,mid,2*k,cnt)+query(mid+1,r,2*k+1,cnt);
        if(tmp>=10)
            cnt++;
        return tmp%10;
    }
}
int main()
{
    int n,q;
    while(~scanf("%d",&n))
    {
        build(1,n,1);
//        printf("YESSS\n");
        scanf("%d",&q);
        int l,r;
        while(q--)
        {
            scanf("%d%d",&l,&r);
            int ans=0;
            query(l,r,1,ans);
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll int
#define pp pair <ll,ll>

using namespace std;
map <pp,ll> m;
map <pp,ll> msum;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n , k , i;

    cin >> n;
    ll a[n];
    for (i = 0 ; i < n ; i++)
    {
        cin >> a[i];
        m[{i,i}] = (ll)0;
        msum[{i,i}] = a[i];
    }
    k = n;
    ll lengthpossible = 0;
    while(k)
    {
        k/=2;
        lengthpossible++;
    }
    ll current = 2;
    ll count = 1;
    while (count < lengthpossible)
    {
        for (i = 0 ; ; i++)
        {

            if ((i+current-1)>= n)
            break;

            m[{i,i+current-1}] = m[{i,i + (current/2) -1}] + m[{i+(current/2),i+current-1}];

            if ((msum[{i,i + (current/2) -1}] + msum[{i+(current/2),i+current-1}]) >= 10)
           {
               m[{i,i+current-1}]++;
           }
            msum[{i,i+current-1}] =  (msum[{i,i + (current/2) -1}] + msum[{i+(current/2),i+current-1}])%10;
        }
        current *= 2;
        count++;
    }
    ll q;
    cin >> q;
    ll x , y;

    while (q--)
    {
        cin >> x >> y;
        x--;
        y--;
        // pp mf = make_pair(x,y);
        cout << m[{x,y}] << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll int
#define pp pair <ll,ll>

using namespace std;
map <pp,ll> m;
map <pp,ll> msum;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n , k , i;

    cin >> n;
    ll a[n];
    for (i = 0 ; i < n ; i++)
    {
        cin >> a[i];
        m[{i,i}] = (ll)0;
        msum[{i,i}] = a[i];
    }
    ll lengthpossible = log(n)/log(2);
    ll current = 2;
    lengthpossible++;
    ll count = 1;
    while (count < lengthpossible)
    {
        for (i = 0 ; ; i++)
        {
            // if (current == 2 && i == 1)
            //     cout << (msum[make_pair(i,i + (current/2) -1)] + msum[make_pair(i+(current/2),i+current-1)]) << "\n";

            if ((i+current-1)>= n)
            break;

            m[{i,i+current-1}] = m[{i,i + (current/2) -1}] + m[{i+(current/2),i+current-1}];

            if ((msum[{i,i + (current/2) -1}] + msum[{i+(current/2),i+current-1}]) >= 10)
           {
               m[{i,i+current-1}]++;
           }
            msum[{i,i+current-1}] =  (msum[{i,i + (current/2) -1}] + msum[{i+(current/2),i+current-1}])%10;
        }
        current *= 2;
        count++;
    }
    ll q;
    cin >> q;
    ll x , y;

    while (q--)
    {
        cin >> x >> y;
        x--;
        y--;
        // pp mf = make_pair(x,y);
        cout << m[{x,y}] << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pp pair <ll,ll>
using namespace std;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n , k , i;
map <pp,ll> m;
map <pp,ll> msum;

    cin >> n;
    ll a[n];
    for (i = 0 ; i < n ; i++)
    {
        cin >> a[i];
        m[{i,i}] = (ll)0;
        msum[{i,i}] = a[i];
    }
    ll lengthpossible = log(n)/log(2);
    ll current = 2;
    lengthpossible++;
    ll count = 1;
    while (count < lengthpossible)
    {
        for (i = 0 ; ; i++)
        {
            // if (current == 2 && i == 1)
            //     cout << (msum[make_pair(i,i + (current/2) -1)] + msum[make_pair(i+(current/2),i+current-1)]) << "\n";

            if ((i+current-1)>= n)
            break;

            m[{i,i+current-1}] = m[{i,i + (current/2) -1}] + m[{i+(current/2),i+current-1}];

            if ((msum[{i,i + (current/2) -1}] + msum[{i+(current/2),i+current-1}]) >= 10)
           {
               m[{i,i+current-1}]++;
           }
            msum[{i,i+current-1}] =  (msum[{i,i + (current/2) -1}] + msum[{i+(current/2),i+current-1}])%10;
        }
        current *= 2;
        count++;
    }
    ll q;
    cin >> q;
    ll x , y;

    while (q--)
    {
        cin >> x >> y;
        x--;
        y--;
        // pp mf = make_pair(x,y);
        cout << m[{x,y}] << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pp pair <ll,ll>
using namespace std;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n , k , i;
    //submit
map <pp,ll> m;
map <pp,ll> msum;

    cin >> n;
    ll a[n];
    for (i = 0 ; i < n ; i++)
    {
        cin >> a[i];
        m[{i,i}] = (ll)0;
        msum[{i,i}] = a[i];
    }
    ll lengthpossible = log(n)/log(2);
    ll current = 2;
    lengthpossible++;
    ll count = 1;
    while (count < lengthpossible)
    {
        for (i = 0 ; ; i++)
        {
            // if (current == 2 && i == 1)
            //     cout << (msum[make_pair(i,i + (current/2) -1)] + msum[make_pair(i+(current/2),i+current-1)]) << "\n";

            if ((i+current-1)>= n)
            break;

            m[{i,i+current-1}] = m[{i,i + (current/2) -1}] + m[{i+(current/2),i+current-1}];

            if ((msum[{i,i + (current/2) -1}] + msum[{i+(current/2),i+current-1}]) >= 10)
           {
               m[{i,i+current-1}]++;
           }
            msum[{i,i+current-1}] =  (msum[{i,i + (current/2) -1}] + msum[{i+(current/2),i+current-1}])%10;
        }
        current *= 2;
        count++;
    }
    ll q;
    cin >> q;
    ll x , y;

    while (q--)
    {
        cin >> x >> y;
        x--;
        y--;
        // pp mf = make_pair(x,y);
        cout << m[{x,y}] << "\n";
    }

    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
const int maxn = 100005;
int array[maxn];
int buf[maxn];
int get_candies(const int l, const int r, int &candies){
    int remain;
    int length = r - l + 1;
    bool first_flag = true;
    int *i_p;
    while(length > 1){
        length >>= 1;
        if(first_flag)
            i_p = (array + l - 1);
        else
            i_p = buf;
        for(int j = 0; j < length; ++j){
            if(i_p[j * 2] + i_p[j * 2 + 1] >= 10)
                ++candies;
            buf[j] = (i_p[j * 2] + i_p[j * 2 + 1]) % 10;
        }
        first_flag = false;
    }
    remain = buf[0];
    return remain;
}
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i)
        cin >> array[i];
    // // 进行构建
    // for(int i = 0; i < n; ++i){
    //     int numbers = 1;

    // }
    int queries;
    cin >> queries;
    int l, r;
    bool first_flag;
    int *i_p;
    for(int i = 0; i < queries; ++i){
        int candies = 0;
        cin >> l >> r;
        int length = r - l + 1;
        int remain = array[l - 1];
        int _remain;
        int pos = l;
        for(int j = 1; j < length; j <<= 1){
            _remain = get_candies(pos + 1, pos + j, candies);
            if(remain + _remain >= 10)
                ++candies;
            remain = (remain + _remain) % 10;
            pos = pos + j;
        }
        cout << candies << endl;
    }
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
const int maxn = 100005;
int array[maxn];
int buf[maxn];
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i)
        cin >> array[i];
    // // 进行构建
    // for(int i = 0; i < n; ++i){
    //     int numbers = 1;

    // }
    int queries;
    cin >> queries;
    int l, r;
    bool first_flag;
    int *i_p;
    for(int i = 0; i < queries; ++i){
        int candies = 0;
        cin >> l >> r;
        int length = r - l + 1;
        first_flag = true;
        // int pos = l;
        while(length > 1){
            length >>= 1;
            if(first_flag)
                i_p = (array + l - 1);
            else
                i_p = buf;
            for(int j = 0; j < length; ++j){
                if(i_p[j * 2] + i_p[j * 2 + 1] >= 10)
                    ++candies;
                buf[j] = (i_p[j * 2] + i_p[j * 2 + 1]) % 10;
            }
            first_flag = false;
        }
        cout << candies;
    }
    return 0;
}


#include <iostream>
using namespace std;
const int maxn = 2e5;
int pre_sum[maxn];
int main(){
    int n;
    cin >> n;
    pre_sum[0] = 0;
    for(int i = 1; i <= n; ++i){
        int num;
        cin >> num;
        pre_sum[i] = pre_sum[i - 1] + num;
    }
    int q;
    cin >> q;
    while(q--){
        int l, r;
        cin >> l >> r;
        int sum = pre_sum[r] - pre_sum[l - 1];
        cout << sum / 10 << endl;
    }
}


#include <iostream>
#include <cmath>
using namespace std;
const int maxn = 100005;
int array[maxn];
int buf[maxn];
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i)
        cin >> array[i];
    // // 进行构建
    // for(int i = 0; i < n; ++i){
    //     int numbers = 1;

    // }
    int queries;
    cin >> queries;
    int l, r;
    bool first_flag;
    int *i_p;
    for(int i = 0; i < queries; ++i){
        int candies = 0;
        cin >> l >> r;
        int length = r - l + 1;
        first_flag = true;
        // int pos = l;
        while(length > 1){
            length >>= 1;
            if(first_flag)
                i_p = (array + l - 1);
            else
                i_p = buf;
            for(int j = 0; j < length; ++j){
                if(i_p[j * 2] + i_p[j * 2 + 1] >= 10)
                    ++candies;
                buf[j] = (i_p[j * 2] + i_p[j * 2 + 1]) % 10;
            }
            first_flag = false;
        }
        cout << candies << endl;
    }
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
const int maxn = 100005;
int array[maxn];
int buf[maxn];
int get_candies(const int l, const int r, int &candies){
    int remain;
    int length = r - l + 1;
    bool first_flag = true;
    int *i_p;
    buf[0] = array[l - 1];
    while(length > 1){
        length >>= 1;
        if(first_flag)
            i_p = (array + l - 1);
        else
            i_p = buf;
        for(int j = 0; j < length; ++j){
            if(i_p[j * 2] + i_p[j * 2 + 1] >= 10)
                ++candies;
            buf[j] = (i_p[j * 2] + i_p[j * 2 + 1]) % 10;
        }
        first_flag = false;
    }
    remain = buf[0];
    return remain;
}
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i)
        cin >> array[i];
    // // 进行构建
    // for(int i = 0; i < n; ++i){
    //     int numbers = 1;

    // }
    int queries;
    cin >> queries;
    int l, r;
    bool first_flag;
    int *i_p;
    for(int i = 0; i < queries; ++i){
        int candies = 0;
        cin >> l >> r;
        int length = r - l + 1;
        int remain = array[l - 1];
        int _remain;
        int pos = l;
        for(int j = 1; j < length; j <<= 1){
            _remain = get_candies(pos + 1, pos + j, candies);
            if(remain + _remain >= 10)
                ++candies;
            remain = (remain + _remain) % 10;
            pos = pos + j;
        }
        cout << candies << endl;
    }
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
const int maxn = 100005;
int array[maxn];
int buf[maxn];
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i)
        cin >> array[i];
    // // 进行构建
    // for(int i = 0; i < n; ++i){
    //     int numbers = 1;

    // }
    int queries;
    cin >> queries;
    int l, r;
    bool first_flag;
    int *i_p;
    for(int i = 0; i < queries; ++i){
        int candies = 0;
        cin >> l >> r;
        int length = r - l + 1;
        first_flag = true;
        // int pos = l;
        while(length > 1){
            length <<= 1;
            if(first_flag)
                i_p = (array + l - 1);
            else
                i_p = buf;
            for(int j = 0; j < length; ++j){
                if(i_p[j * 2] + i_p[j * 2 + 1] >= 10)
                    ++candies;
                buf[j] = (i_p[j * 2] + i_p[j * 2 + 1]) % 10;
            }
            first_flag = false;
        }
        cout << candies;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    vector<vector<pair<int, int>>> dp(20);
    int cur = 1;
    for (int i = 0; i < n; i++)
    {
        dp[0].push_back(make_pair(arr[i], 0));
    }
    for (int deg = 1; deg < 20; deg++)
    {
        cur *= 2;
        for (int i = 0; i + cur <= n; i++)
        {
            int left1 = dp[deg - 1][i].first;
            int left2 = dp[deg - 1][i + cur / 2].first;
            int candies1 = dp[deg - 1][i].second;
            int candies2 = dp[deg - 1][i + cur / 2].second;
            int res_candies = candies1 + candies2;
            int res_left = (left1 + left2) % 10;
            if (left1 + left2 >= 10)
                res_candies++;
            dp[deg].push_back(make_pair(res_left, res_candies));
        }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int l, r;
        cin >> l >> r;
        int deg = 0;
        int len = r - l + 1;
        while (len % 2 == 0)
        {
            deg++;
            len /= 2;
        }
        cout << dp[deg][l - 1].second << "\n";
    }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    vector<vector<pair<int, int>>> dp(20);
    int cur = 1;
    for (int i = 0; i < n; i++)
    {
        dp[0].push_back(make_pair(arr[i], 0));
    }
    for (int deg = 1; deg <= 20; deg++)
    {
        for (int i = 0; i + cur <= n; i++)
        {
            int left1 = dp[deg - 1][i].first;
            int left2 = dp[deg - 1][i + cur].first;
            int candies1 = dp[deg - 1][i].second;
            int candies2 = dp[deg - 1][i + cur].second;
            int res_candies = candies1 + candies2;
            int res_left = (left1 + left2) % 10;
            if (left1 + left2 >= 10)
                res_candies++;
            dp[deg].push_back(make_pair(res_left, res_candies));
        }
        cur *= 2;
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int l, r;
        cin >> l >> r;
        int deg = 0;
        int len = r - l + 1;
        while (len % 2 == 0)
        {
            deg++;
            len /= 2;
        }
        cout << dp[deg][l - 1].second << "\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5;
int arr[maxN];

int solve(int a, int b)
{
    int ans = 0;
    vector<int> v;
    for (int i = a; i < b; i += 2)
    {
        int s = arr[i] + arr[i + 1];
        if (s >= 10)
        {
            ans++;
        }
        s %= 10;
        v.push_back(s);
    }
    queue<int> q;
    while (v.size() > 1)
    {
        int num1, num2;
        num1 = v.back();
        v.pop_back();
        num2 = v.back();
        v.pop_back();
        int s = num1 + num2;
        if (s >= 10)
        {
            ans++;
        }
        s %= 10;
        q.push(s);
        if (v.empty())
        {
            while (!q.empty())
            {
                v.push_back(q.front());
                q.pop();
            }
        }
    }
    return ans;
}
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int a, b;
        cin >> a >> b;
        cout << solve(a, b) << "\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5;
int arr[maxN];

int solve(int a, int b)
{
    int ans = 0;
    vector<int> v;
    for (int i = a; i < b; i += 2)
    {
        int s = arr[i - 1] + arr[i];
        if (s >= 10)
        {
            ans++;
        }
        s %= 10;
        v.push_back(s);
    }
    queue<int> q;
    while (v.size() > 1)
    {
        int num1, num2;
        num1 = v.back();
        v.pop_back();
        num2 = v.back();
        v.pop_back();
        int s = num1 + num2;
        if (s >= 10)
        {
            ans++;
        }
        s %= 10;
        q.push(s);
        if (v.empty())
        {
            while (!q.empty())
            {
                v.push_back(q.front());
                q.pop();
            }
        }
    }
    return ans;
}
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int a, b;
        cin >> a >> b;
        cout << solve(a, b) << "\n";
    }
}


#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e5 + 5;

int n,q,a[maxn];
struct node {
  int tot, cnt;
} t[maxn*4];

void build(int v, int l, int r) {
  if (l==r) {
    t[v].tot = a[l];
    t[v].cnt = 0;
  } else {
    int m = (l+r)/2;
    build(2*v,l,m);
    build (2*v+1,m+1,r);
    t[v].cnt = t[2*v].cnt + t[2*v+1].cnt;
    t[v].tot = t[2*v].tot + t[2*v+1].tot;
    if (t[v].tot >= 10) {
      t[v].cnt ++;
    }
    t[v].tot %= 10;
  }
}

node query(int v,int tl, int tr, int l, int r) {
  if (r<tl || l>tr) return {0,0};
  if (l<=tl && tr<=r) return t[v];
  int tm = (tl+tr)/2;
  node left = query(2*v, tl, tm, l, r);
  node right =  query(2*v+1, tm+1, tr, l, r);
  int tot = left.tot + right.tot;
  return {tot%10, left.cnt+right.cnt+(tot>=10) };
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

  cin>>n;
  for (int i=1; i<=n; i++) {
    cin>>a[i];
  }

  build(1,1,n);

  cin>>q;
  while(q--) {
    int l,r; cin>>l>>r;
    cout<<query(1,1,n,l,r).cnt<<"\n";
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
const int maxh = 21;

int n, a[maxn];
int table[maxn][maxh], sum[maxn][maxh];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

  cin>>n;
  for (int i=1; i<=n; i++) {
    cin>>a[i];
    sum[i][0] = a[i];
    table[i][0] = 0;
  }

  for (int j=1; j<maxh; j++) {
    int len = 1<<j;
    for (int i=1; i+len-1<=n; i++) {
      table[i][j] = table[i][j-1] + table[i+len/2][j-1];
      sum[i][j] = sum[i][j-1] + sum[i+len/2][j-1];
      if (sum[i][j]>=10) {
	table[i][j]++;
      }
      sum[i][j] %= 10;
    }
  }

  int q;
  cin>>q;
  while (q--) {
    int l,r; cin>>l>>r;
    int h = 0;
    int dist = r-l+1;
    while (dist>1) {
      dist = dist>>1;
      h++;
    }
    cout<<table[l][h]<<'\n';
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n,a[maxn];

map<pair<int,int>, int> cache;
map<pair<int,int>,int> sums;

bool ispow2(int x) {
  return (x&(x-1))==0;
}

bool valid(int l, int r) {
  if (l>r) return false;
  if (l<1 || l>n) return false;
  if (r<1 || r>n) return false;
  return true;
}

int f(int l, int r) {
  //if (l>r) return 0;
  if (cache.find({l,r}) != cache.end()) {
    return cache[{l,r}];
  }
  if (l==r) {
    cache[{l,r}]=0;
    return sums[{l,r}]=a[l];
  } else {
    if (!ispow2(r-l+1)) {
      cout<<l<<","<<r<<endl;
    }
    int mid = (l+r)/2;
    int len = mid-l+1;
    for (int x=l; x<=r; x++) {
      int y = x+len-1;
      if (y>r) break;
      f(x,y);
    }
    int sm = sums[{l,mid}]+sums[{mid+1,r}];
    cache[{l,r}]=cache[{l,mid}]+cache[{mid+1,r}];
    if (sm>=10) cache[{l,r}]++;
    return sums[{l,r}] = sm%10;
  }

}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

  cin>>n;
  for (int i=1; i<=n; i++) {
    cin>>a[i];
  }

  int run = 1;
  while (run*2 <= n) {
    run*=2;
  }

  for (int x=1; x<=n; x++) {
    int y = x+run-1;
    if (y>n) break;
    f(x,y);
  }

  // for (auto p: cache) {
  //   int l = p.first.first; int r = p.first.second;
  //   if (r-l+1 == 2) {
  //     cout<<l<<","<<r<<": ";
  //     cout<<cache[{l,r}]<<" "<<sums[{l,r}]<<endl;
  //   }
  // }

  int q; cin>>q;
  while (q--) {
    int l, r; cin>>l>>r;
    cout<<cache[{l,r}]<<'\n';
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
const int maxh = 21;

int n, a[maxn];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

  cin>>n;
  vector<int> prefix = {0};
  for (int i=1; i<=n; i++) {
    cin>>a[i];
    prefix.push_back(prefix.back()+a[i]);
  }

  int q; cin>>q; while (q--) {
    int l, r; cin>>l>>r;
    int ans = (prefix[r] - prefix[l-1])/10;
    cout<<ans<<'\n';
  }

  return 0;
}