#include <bits/stdc++.h>   using namespace std;   struct node;   typedef node *Node;   const int inf = 1000000;   bool fl = 0;   struct node {     Node left, right, link, parent;     int size, prior, sum, number;     set<int> all;     pair<int, int> mmin;     node(int number) : number(number) {       left = right = link = parent = NULL;       prior = rand() + (rand() << 16);       update();     }     int key() {       int ans = 1;       if (left) ans += left->size;       return ans;     }     void update() {       size = 1;       sum = all.size();       if (sum == 0)         mmin = make_pair(inf, inf);       else         mmin = make_pair(*all.begin(), number);       if (left) {         size += left->size;         sum += left->sum;         mmin = min(mmin, left->mmin);         left->parent = this;       }       if (right) {         size += right->size;         sum += right->sum;         mmin = min(mmin, right->mmin);         right->parent = this;       }     }   };   void upd_min(Node t) {     while (t) {       t->update();       t = t->parent;     }   }   void add_ppl(Node &t, int ppl) {     t->all.insert(ppl);     t->sum++;     upd_min(t);   }   void del_ppl(Node &t, int ppl) {     t->all.erase(ppl);     t->sum--;     upd_min(t);   }   Node merge(Node l, Node r) {     if (!l) return r;     if (!r) return l;     if (l->prior > r->prior) {       l->right = merge(l->right, r);       l->update();       return l;     } else {       r->left = merge(l, r->left);       r->update();       return r;     }   }   void split(Node t, int key, Node &l, Node &r) {     if (!t) return void(l = r = NULL);     if (t->key() <= key) {       split(t->right, key - t->key(), t->right, r);       l = t;     } else {       split(t->left, key, l, t->left);       r = t;     }     t->update();     t->parent = NULL;   }   int get_pos(Node t) {     vector<char> vc;     Node v = t;     while (v->parent) {       if (v->parent->left == v)         vc.push_back(0);       else         vc.push_back(1);       v = v->parent;     }     reverse(vc.begin(), vc.end());     int pos = 0;     for (int i = 0; i < vc.size(); ++i) {       if (vc[i] == 0)         v = v->left;       else         pos += v->key(), v = v->right;     }     pos += v->key();     return pos;   }   Node get_root(Node t) {     Node ans = NULL;     while (t) {       ans = t;       t = t->parent;     }     return ans;   }   Node leftmost(Node t) {     Node ans = NULL;     while (t) {       ans = t;       t = t->left;     }     return ans;   }   Node rightmost(Node t) {     Node ans = NULL;     while (t) {       ans = t;       t = t->right;     }     return ans;   }   void set_link(Node t, Node v) {     if (!t) return;     t->link = v;   }   void cut_out(Node t) {     int pos = get_pos(t);     Node l, r;     split(get_root(t), pos, l, r);     set_link(leftmost(r), t);   }   void cut_out1(Node t) {     int pos = get_pos(t);     Node l, r;     split(get_root(t), pos - 1, l, r);     set_link(leftmost(r), rightmost(l));   }   void expose(Node v) {     cut_out(v);     v = leftmost(get_root(v));     while (v->link) {       cut_out(v->link);       merge(get_root(v->link), get_root(v));       set_link(v, NULL);       v = leftmost(get_root(v));     }   }   void link(Node u, Node v) {     set_link(u, v);     expose(u);   }   void cut(Node u, Node v) {     expose(v);     set_link(u, NULL);   }   Node lca(Node v, Node u, bool &one_tree) {     expose(u);     if (get_root(u) == get_root(v)) {       one_tree = 1;       return v;     }     expose(v);     expose(u);     return leftmost(get_root(v))->link;   }   vector<Node> nodes;   const int maxn = 100000;   vector<pair<int, int> > add;   vector<int> g[maxn + 1];   vector<int> deep;   void dfs(int v, int p = -1) {     for (int i = 0; i < g[v].size(); ++i) {       int tv = g[v][i];       if (tv == p) continue;       deep[tv] = deep[v] + 1;       dfs(tv, v);     }   }   void print_(Node v) {     if (!v) return;     print_(v->left);     cout <<   t  << v->number <<     << (v->link ? v->link->number : -1) << endl;     print_(v->right);   }   void print(Node v) { print_(get_root(v)); }   void print_all(int n) {     for (int i = 1; i <= n; ++i) {       cout << i <<  : n ;       print(nodes[i]);       cout << endl;     }   }   void do_the_thing(Node v, int x) {     Node t = get_root(v);     int k = min(x, t->sum);     cout << k <<    ;     vector<pair<int, int> > add_after;     for (int i = 0; i < k; ++i) {       pair<int, int> cmin = t->mmin;       cout << cmin.first <<    ;       del_ppl(nodes[cmin.second], cmin.first);       add_after.push_back(cmin);     }     cout << endl;     for (int i = 0; i < add_after.size(); ++i) {       pair<int, int> ct = add_after[i];       add_ppl(nodes[ct.second], ct.first);     }   }   int main() {     srand(time(NULL));     ios_base::sync_with_stdio(0);     int n, m, q;     cin >> n >> m >> q;     nodes.resize(n + 1);     deep.assign(n + 1, 0);     for (int i = 1; i <= n; ++i) nodes[i] = new node(i);     for (int i = 0; i < n - 1; ++i) {       int a, b;       cin >> a >> b;       add.push_back(make_pair(a, b));       g[a].push_back(b);       g[b].push_back(a);     }     dfs(1);     for (int i = 0; i < add.size(); ++i) {       int a = add[i].first;       int b = add[i].second;       if (deep[a] < deep[b]) swap(a, b);       link(nodes[a], nodes[b]);     }     for (int i = 1; i <= m; ++i) {       int city;       cin >> city;       add_ppl(nodes[city], i);     }     for (int i = 0; i < q; ++i) {       int v, u, x;       cin >> v >> u >> x;       bool one_tree = 0;       Node t = lca(nodes[v], nodes[u], one_tree);       if (one_tree) {         cut_out1(nodes[v]);         do_the_thing(nodes[v], x);       } else {         int split_key = get_root(nodes[v])->size;         cut_out1(t);         merge(get_root(nodes[v]), get_root(t));         do_the_thing(nodes[v], x);         Node l, r;         split(get_root(nodes[v]), split_key, l, r);       }     }     return 0;   }   