#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = 3.14159265358979323846;
int main() {
  int N;
  cin >> N;
  long long sum = 0;
  map<int, int> m;
  for (int i = 0; i < N; i++) {
    int Ai;
    cin >> Ai;
    ++m[Ai];
    sum += Ai;
  }
  int Q;
  cin >> Q;
  vector<int> lut(100001);
  for (int i = 0; i < lut.size(); i++) {
    lut[i] = i;
  }
  long long ans = sum;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    map<int, int>::iterator itr = m.find(B);
    if (itr != m.end()) {
      int n = itr->second;
      int orgValue = itr->first * n;
      int newValue = C * n;
      m[B] = 0;
      m[C] += n;
      sum = sum - orgValue + newValue;
      cout << sum << endl;
    } else {
      cout << sum << endl;
    }
  }
  return 0;
}
