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

int maxN = 100000, N, M;
vector<vector<pair<int,int>>> G(maxN,vector<pair<int,int>>(0));
vector<int> A(maxN,-1);

void dfs(int u, int pre, int e){
  if(G[pre][e].second == A[pre]){
    A[u] = G[pre][e].second + 1;
    if(A[u]>N) A[u] = 1;
  }
  else A[u] = G[pre][e].second;
  
  for(int i=0;i<G[u].size();i++){
    pair<int,int> p = G[u][i];
    if(A[p.first]!=-1) continue;
    dfs(p.first,u,i);
  }
  return;
}

int main(){
  cin >> N >> M;
  for(int i=0;i<M;i++){
    int u,v,c;
    cin >> u >> v >> c;
    u--;v--;
    G[u].push_back(make_pair(v,c));
    G[v].push_back(make_pair(u,c));
  }
  
  dfs(0,G[0][0].first,0);
  
  for(int i=0;i<N;i++) cout << A[i] << endl;
  return 0;
}

#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<ctime>
#include<cstdlib>
#include<fstream>
#define INF 1001001001001001001
#define MAX 50000001
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main() {
	int n, m, q;
	cin >> n >> m >> q;
	vector<pair<int, int>>budget;
	int x, y;
	rep(i, 0, n) {
		cin >> x >> y;
		budget.push_back({ x,y });
	}
	sort(budget.begin(), budget.end());
	vector<int>box(m + 1, 0);
	rep(i, 1, m + 1)cin >> box[i];
	long long ans;
	vector<long long>A;
	rep(i, 0, q) {
		ans = 0;
		cin >> x >> y;
		vector<int>ibox;
		rep(i, 1, x)ibox.push_back(box[i]);
		rep(i, y + 1, m + 1)ibox.push_back(box[i]);
		sort(ibox.begin(), ibox.end());
//		cout << "done" << endl;
		int a = 0; 
		vector<int>now;
		rep(j, 0, ibox.size()) {
			while (a < n && budget[a].first <= ibox[j]) {
				now.push_back(budget[a].second);
				a++;
			}
			sort(now.rbegin(), now.rend());
			if (!now.empty()) {
				ans += now[0];
				now[0] = 0;
			}
		}
		A.push_back(ans);
	}
	rep(i, 0, A.size())cout << A[i] << endl;
}