#include <bits/stdc++.h>
using namespace std;
int main() {
   int N;
   cin >> N;
   vector<int> A(N);
   int count = N;
   for (int i = 0; i < count; i++)
   {
       cin >> A.at(i);
       /* code */
   }
   int Q;
   cin >> Q;
   vector<int> B(Q);
   vector<int> C(Q);
   count = Q;
   for (int i = 0; i < count; i++)
   {
       cin >> B.at(i) >> C.at(i);
       /* code */
   }
   count = N;
   vector<int64_t> S(Q);
   for(int j = 0; j < Q; j++{
       for (int i = 0; i < count; i++){
           if(A.at(i) == B.at(j) ){
               A.at(i) = C.at(j);
           }
           S.at(j) += A.at(i);
       }
   cout << S.at(j) << endl;
   }  
   

   
}