#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000001;
struct edge {
  int to, cost;
};
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
struct Road {
  double cost;
  int a, b;
};
struct pos {
  int x, y, sx, sy, cost;
};
int d[100001] = {};
int main() {
  int n, q;
  cin >> n;
  long long t = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    d[a]++;
    t += a;
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    d[c] += d[b];
    t -= d[b] * b;
    t += d[b] * c;
    d[b] = 0;
    cout << t << endl;
  }
  return 0;
}
