#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7, INF = 1e9;
int main() {
  int n;
  cin >> n;
  vector<long long int> v(n);
  map<int, int> m;
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    sum += v[i];
    m[v[i]]++;
  }
  vector<long long int> z;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    int d = b - a;
    int cnt = m[a];
    sum += d * cnt;
    m[b] += cnt;
    z.emplace_back(sum);
  }
  for (long long int x : z) {
    cout << x << endl;
  }
  system("pause");
}
