import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[] a = new long[n]; for(int i = 0; i < n; i++) a[i] = sc.nextLong(); int[] gt = new int[n]; gt[0] = 0; int[] lt = new int[n]; lt[0] = 0; for(int i = 1; i < n; i++){ if(a[i-1] <= a[i]) gt[i] = 1; if(a[i-1] >= a[i]) lt[i] = 1; gt[i] += gt[i-1]; lt[i] += lt[i-1]; } int q = sc.nextInt(); for(int i = 0; i < q; i++){ int l = sc.nextInt(); int r = sc.nextInt(); boolean asc = (gt[r]-gt[l] == r-l); boolean dec = (lt[r]-lt[l] == r-l); int ans = 2; if(asc && dec) ans = 0; else if(asc) ans = 1; else if(dec) ans = -1; System.out.println(ans); } } }