import java.io.IOException; import java.io.InputStreamReader; import java.io.BufferedReader; public class Main{ public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] line = br.readLine().split(" "); if(line.length != n) System.exit(1); long[] a = new long[n]; for(int i = 0; i < n; i++) a[i] = Long.parseLong(line[i]); 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 = Integer.parseInt(br.readLine()); for(int i = 0; i < q; i++){ line = br.readLine().split(" "); int l = Integer.parseInt(line[0]), r = Integer.parseInt(line[1]); 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); } } }