import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
int mkk = sc.nextInt();
while(mkk>0) {
int bs = sc.nextInt();
int f =LowerBound(a, bs);
int h = Upperbound(a,bs);
System.out.print(f+" "+h);
System.out.println();
mkk--;
}
}
public static int LowerBound(int[] a, int m) {
int lo = 0;
int hi = a.length - 1;
int res = -1;
if(m>a[hi]) {
return -1;
}
while (lo <= hi) {
int mid = lo + hi / 2;
if (a[mid] == m) {
res = mid;
hi = mid - 1;
}
else if (m<a[mid]) {
hi = mid-1;
}else {
lo = mid+1;
}
}
return res;
}
public static int Upperbound(int[]a, int m1) {
int lo = 0;
int hi = a.length - 1;
int res = -1;
if(m1>a[hi]) {
return -1;
}
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (a[mid] == m1) {
res = mid;
lo = mid + 1;
}
else if (m1<a[mid]) {
hi = mid-1;
}else {
lo = mid+1;
}
}
return res;
}
}