#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long pw(long long a, long long b, long long p) {
  if (b == 0) return 1;
  long long t = pw(a, b / 2, p);
  if (b % 2)
    return ((a * t * t) % p);
  else
    return ((t * t) % p);
}
long long cost[100005], vis[100005], ini[100005], lb[100005];
long long abmc = 0, abtw = 1;
vector<long long> v[100005];
pair<long long, pair<long long, long long> > dfs(long long z, long long iniz,
                                                 long long lev) {
  if (vis[z]) {
    if (ini[z] != iniz) return {-1, {-1, 1}};
    return {lb[z], {-1, 1}};
  }
  vis[z] = 1;
  lb[z] = lev;
  ini[z] = iniz;
  long long cmi = -1, mc = -1, tw = 1;
  for (long long k : v[z]) {
    pair<long long, pair<long long, long long> > t = dfs(k, iniz, lev + 1);
    if (t.first == -1) continue;
    if (cmi == -1 || t.first < cmi) cmi = t.first;
    if (t.second.first == -1) continue;
    if (mc == -1 || t.second.first < mc) {
      mc = t.second.first;
      tw = t.second.second;
    } else if (mc == t.second.first)
      tw += t.second.second;
  }
  lb[z] = cmi;
  if (cmi == -1) {
    abmc += cost[z];
  } else if (cmi <= lev) {
    if (cost[z] < mc || mc == -1) {
      mc = cost[z];
      tw = 1;
    } else if (cost[z] == mc)
      tw++;
  }
  if (cmi == lev) {
    cmi = -1;
    abmc += mc;
    abtw = (abtw * tw) % 1000000007;
    mc = -1;
    tw = 1;
  }
  return {cmi, {mc, tw}};
}
void solve() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> cost[i];
  }
  long long m;
  cin >> m;
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    v[a].push_back(b);
  }
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i, i, 0);
  }
  cout << abmc << " " << abtw;
}
signed main() {
  ios_base::sync_with_stdio(false);
  long long t = 1;
  while (t--) solve();
  return 0;
}
