#include "ezici.h"
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n,m; cin >> n >> m;
    vector<pair<pair<int, int>, bool>> g;
    for(int i = 0; i < m; i++) {
        int u,v,t; cin >> u >> v >> t;
        g.push_back({{u,v}, t});
    }
    cout << task1(n, m, g) << endl;

    cin >> n;
    vector<long long> p;
    for(int i = 0; i < n-1; i++) {int a; cin >> a; p.push_back(a);}
    cout << task2(p) << endl;

    cin >> n;
    p.clear();
    for(int i = 0; i < n; i++) {long long a; cin >> a; p.push_back(a);}
    cout << task3(p) << endl;

    cin >> n;
    p.clear();
    for(int i = 0; i < n; i++) {long long a; cin >> a; p.push_back(a);}
    cout << task4(p) << endl;
    
    p.clear();
    cin >> n;
    for(int i = 0; i < n; i++) {long long a; cin >> a; p.push_back(a);}
    cout << task5(p) << endl;

    p.clear();
    cin >> n;
    for(int i = 0; i < n; i++) {long long a; cin >> a; p.push_back(a);}
    cout << task6(p) << endl;

    p.clear();
    cin >> n;
    for(int i = 0; i < n; i++) {long long a; cin >> a; p.push_back(a);}
    cout << task7(p) << endl;

    p.clear();
    cin >> n;
    for(int i = 0; i < n; i++) {long long a; cin >> a; p.push_back(a);}
    vector<long long> ans=task8(p);
    for(auto &x : ans) cout << x << " ";
    cout << endl;

    p.clear();
    cin >> n;
    for(int i = 0; i < n; i++) {long long a; cin >> a; p.push_back(a);}
    cout << task9(p) << endl;

    p.clear();
    cin >> n;
    for(int i = 0; i < n; i++) {long long a; cin >> a; p.push_back(a);}
    cout << task10(p) << endl;
}