An interval graph is the intersection graph of a family F={I1,I2,…,In} of closed intervals on the real line. Two vertices vi and vj are joined by an edge exactly when the corresponding intervals Ii and Ij intersect. The family F is called an interval representation of the graph. A unit interval graph is an interval graph for which some interval representation has all intervals of the same length. Figure 1 shows a unit interval graph together with an interval representation of it.

(a) A unit interval graph G.

(b) An interval representation of the graph G.
Figure 1. A unit interval graph and its interval representation.
The closed neighbourhood N[vi] of a vertex vi of a graph G is the set of vertices adjacent to vi together with vi itself, that is, N[vi]={vi}∪{vj:vjvi∈E(G)}. For the graph G of Figure 1(a), N[v1]={v1,v2,v3} and N[v5]={v2,v3,v4,v5,v6}.
Write ρ(vi) for the position of vi in an ordering of the vertices. Under the ordering (v1,v2,…,v17) of the vertices of G, in which ρ(vi)=i for every vi, the closed neighbourhood N[vi] of every vertex is consecutive: the positions of the vertices in N[vi] are integers that follow one after another, without gaps, from the smallest to the largest. An ordering of the vertices of a graph is consecutive if the closed neighbourhood of every vertex of the graph is consecutive. For the graph G of Figure 1(a), the ordering (v1,v2,…,v15,v17,v16) with v16 and v17 exchanged, where ρ(v17)=16, ρ(v16)=17, and ρ(vi)=i for every other vertex, is consecutive as well. The ordering (v2,v1,v3,v4,…,v17) is not consecutive, because the closed neighbourhood of v5 is not consecutive.
You are given n closed intervals of the same length, I1,I2,…,In, listed in non-decreasing order of their left endpoints, and an ordering (vi1,vi2,…,vin) of the vertices of the unit interval graph defined on those n intervals. Write a program that decides whether the ordering is consecutive.
Your program reads from standard input. The input consists of T test cases, and T is given on the first line.
Each test case begins with a line containing two positive integers n and l, the number of intervals and their common length, where n is at most 100,000 and l is at most 100,000,000. The next n lines contain the left endpoints of I1,I2,…,In, one per line, and the left endpoint of Ii is less than or equal to the left endpoint of Ij whenever i<j. Every endpoint, left or right, lies between -100,000,000 and 100,000,000, inclusive. The following n lines contain an ordering of the vertices of the unit interval graph defined on those intervals, one vertex number per line, from the first position to the last.
Your program writes to standard output. For each test case, print exactly one line containing an integer that tells whether the given ordering is consecutive. Print 1 if it is, and -1 otherwise.