#include <stdio.h>

int main() {
    int t;
    scanf("%d", &t);

    for(int i=0; i<t; i++) {
        int n, m, cnt[100010]={}, flag=1;

        scanf("%d %d", &n, &m);
        for(int i=0; i<n; i++) {
            int l;
            scanf("%d", &l);
            for(int j=0; j<l; j++) {
                int a;
                scanf("%d", &a);
                cnt[a]++;
            }
        }

        for(int i=1; i<=m; i++) {
            if(cnt[i]<3) {
                flag=0; break;
            }
        }

        if(flag) printf("YES\n");
        else printf("NO\n");
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: