import java.io.PrintWriter; import java.util.Scanner; public class Main { static int t, n; static int[] c; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); t = sc.nextInt(); n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } int q = sc.nextInt(); int[] l = new int[q]; int[] r = new int[q]; for (int i = 0; i < q; i++) { l[i] = sc.nextInt() - 1; r[i] = sc.nextInt(); } sc.close(); c = new int[t]; for (int i = 0; i < n; i++) { c[a[i]]++; } for (int i = 1; i < t; i++) { c[i] += c[i - 1]; } PrintWriter pw = new PrintWriter(System.out); for (int i = 0; i < q; i++) { int ans = f(r[i]) - f(l[i]); pw.println(ans); } pw.flush(); } static int f(int x) { int ret = x / t * n; ret += c[x % t]; return ret; } }