#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
const long long MOD = 1e9 + 7;
long long n, m, cnt = 0;
long long a[N], comp[N], vis[N];
vector<long long> g[N], rg[N], v[N];
vector<long long> todo;
void dfs(long long k) {
  vis[k] = 1;
  for (auto it : g[k]) {
    if (!vis[it]) {
      dfs(it);
    }
  }
  todo.push_back(k);
}
void dfs2(long long k, long long val) {
  comp[k] = val;
  v[val].push_back(a[k]);
  for (long long w : rg[k]) {
    if (comp[w] == -1) {
      dfs2(w, val);
    }
  }
}
void sccAddE(long long from, long long to) {
  g[from].push_back(to);
  rg[to].push_back(from);
}
void scc() {
  for (long long i = 1; i <= n; i++) {
    comp[i] = -1;
  }
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
  }
  reverse(todo.begin(), todo.end());
  for (long long i : todo) {
    if (comp[i] == -1) {
      dfs2(i, i);
      cnt++;
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  cin >> m;
  for (long long i = 1; i <= m; i++) {
    long long u, v;
    cin >> u >> v;
    sccAddE(u, v);
  }
  scc();
  long long ans1 = 0;
  long long ans2 = 1;
  for (long long i = 1; i <= n; i++) {
    if (!v[i].size()) continue;
    sort(v[i].begin(), v[i].end());
    long long min1 = v[i][0];
    ans1 += min1;
    cnt = 0;
    for (auto it : v[i])
      if (it == min1) cnt++;
    ans2 *= cnt;
    ans2 %= MOD;
  }
  cout << ans1 << " " << ans2;
}
