#define _CRT_SECURE_NO_WARNINGS #pragma comment(linker, "/stack:16777216") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i) #define REP(i, N) FOR(i, 0, N) #define RREP(i, N) RFOR(i, N, 0) #define FILL(A,value) memset(A,value,sizeof(A)) #define ALL(V) V.begin(), V.end() #define SZ(V) (int)V.size() #define PB push_back #define MP make_pair #define Pi 3.14159265358979 typedef long long Int; typedef unsigned long long UINT; typedef vector VI; typedef pair PII; const int INF = 2000000000; const int MAX = 1000777; const int MAX2 = 2007; const int BASE = 1000000000; int n, m; int P[MAX]; PII A[MAX]; int main() { int cnt; scanf("%d", &cnt); FOR (test,0,cnt) { scanf("%d %d", &n, &m); FOR (i,0,n) { scanf("%d", &P[i]); -- P[i]; } FOR (i,0,m) { int l, r; scanf("%d %d", &l, &r); -- l; -- r; A[i] = MP(l, r); } sort(A, A+m); int l = A[0].first, r = A[0].second; FOR (i,1,m) { if (A[i].first > r) { sort(P+l, P+r+1); l = A[i].first; r = A[i].second; } else r = max(r, A[i].second); } sort(P+l, P+r+1); bool res = 1; FOR (i,0,n) if (P[i] != i) res = 0; printf(res == 1 ? "Possible\n" : "Impossible\n"); } return 0; }