/*
 * This template is valid both in C and in C++,
 * so you can expand it with code from both languages.
 */

#include <stdio.h>
#include <assert.h>

// constraints
#define MAXN 100000

// input data
int N, M, i;
int A[MAXN], P[MAXN], G[MAXN], E[MAXN];

int main() {
/*
    uncomment the following lines if you want to read/write from files
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
*/

    assert(2 == scanf("%d %d", &N, &M));
    for (i=0; i<M; i++)
        assert(1 == scanf("%d", &E[i]));
    for (i=0; i<N; i++)
        assert(3 == scanf("%d %d %d", &A[i], &P[i], &G[i]));
    
    // insert your code here

    for (i=0; i<M; i++) {
        
        // and also here
        
        printf("%d ", 42); // change 42 with actual answer for i-th group
    }
    printf("\n");
    return 0;
}
