#!/usr/bin/env python3 (n, q, m), p, t = map(int, input().split()), list(map(int, input().split())), [int(x) + 1 for x in input().split()] # 'hop': moving between countries without quarantine, usually from a place j to a place i < j, such that p_j <= p_i + m. # 'jump': moving between two arbitrary countries, typically with quarantine. # hop[l][i] Which place we land after 2^l steps to the right starting at i. # This is needed to compute the number of hops needed when we do not quarantine. L, r, inf, jl, best, jr, b = 18, 0, 10 ** 10, [0] * n, t[0], [0] * n + [t[n - 1]], n - 1 hop = [[0] * n for _ in range(L)] # Initialize the first hop. for i in range(n): while r < n - 1 and p[r + 1] <= p[i] + m: r += 1 hop[0][i] = r # Do the recursion for the next layers. for l in range(1, L): for i in range(n): hop[l][i] = hop[l - 1][hop[l - 1][i]] # The number of hops to go from j to i, or inf if this is impossible. def H(i, j): if i > j: i, j = j, i if hop[-1][i] < j: return inf return sum(2 ** l for l in range(L - 1, -1, -1) if hop[l][i] < j and ((i := hop[l][i]) or 1)) + 1 # For each position, find the minimal cost of getting there given that you quarantine. # First find the cost when jumping to a place with lower p and then jumping up. for i in range(0, n): jl[i], best = min(t[i], best + 1), min(t[i], best) # Next find the cost when jumping and then taking some additional hops to the left. for i in range(n - 2, -1, -1): jr[i], b = (t[i], i) if H(i, b) == inf or t[i] < (v := H(i, b) + jr[b]) else (v, b) # Answer all queries. print(*(int(x < y) or min(H(x, y), jl[y], jr[y]) for _ in range(q) for x, y in [[int(i) - 1 for i in input().split()]]))