#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q, i;
  long long Sum = 0;
  cin >> N;
  map<int, int> A;
  for (i = 0; i < N; i++) {
    int a;
    cin >> a;
    A[a]++;
  }
  cin >> Q;
  for (i = 0; i < Q; i++) {
    int b, c;
    cin >> b >> c;
    A[c] += A[b];
    A.erase(b);
  }
  for (i = 0; i < N; i++) {
    int a;
    cin >> a;
    A[a]++;
  }
  for (auto p : A) {
    Sum += p.second;
  }
  cout << Sum << endl;
}
