int main(int argc, char const *argv[]) {
    ios::sync_with_stdio(false);

    int n, m;
    DisjointSet *D;
    while (cin >> n >> m && n != 0) {
        D = new DisjointSet(n);
        for (int i = 0; i < m; ++i) {
            int k;
            cin >> k;
            int a = -1, b;
            for (int j = 0; j < k; ++j) {
                cin >> b;
                if (a != -1) {
                    D->Union(a, b);
                }
                a = b;
            }
        }
        int suspect = 0;
        for (int i = 0; i < n; ++i) {
            suspect += D->Find(i) == D->Find(0);
        }
        cout << suspect << endl;
    }

    return 0;
}
int main(int argc, char const *argv[]) {
    ios::sync_with_stdio(false);

    int t;
    DisjointSet *D;
    cin >> t;
    for (int cs = 0; cs < t; ++cs) {
        int n, m;
        cin >> n >> m;
        D = new DisjointSet(n);
        for (auto& a : D->total) {
            cin >> a;
        }
        for (int i = 0; i < m; ++i) {
            int a, b;
            cin >> a >> b;
            D->Union(a, b);
        }
        string ans = "POSSIBLE";
        for (int i = 0; i < n; ++i) if (D->Find(i) == i && D->total[i] != 0) {
                ans = "IMPOSSIBLE";
            }
        cout << ans << endl;
    }

    return 0;
}