#include <bits/stdc++.h>
using namespace std;
const int MAXN = 120000;
int n, m;
int prices[MAXN], vis[MAXN];
vector<int> adj[MAXN], adjT[MAXN];
const long long MOD = 1000000007;
vector<int> lista;
vector<int> comp[MAXN];
int cnt;
void dfs(int u, int t) {
  vis[u] = 1;
  vector<int>* ff;
  if (!t)
    ff = &adjT[u];
  else {
    ff = &adj[u];
    comp[cnt].push_back(u);
  }
  for (int i = 0; i < (*ff).size(); i++) {
    int v = (*ff)[i];
    if (!vis[v]) dfs(v, t);
  }
  if (!t) lista.push_back(u);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> prices[i];
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adjT[b].push_back(a);
  }
  for (int i = 0; i < n; i++) vis[i] = 0;
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      dfs(i, 0);
    }
  }
  reverse((lista).begin(), (lista).end());
  for (int i = 0; i < n; i++) vis[i] = 0;
  cnt = 0;
  for (int i = 0; i < n; i++) {
    if (!vis[lista[i]]) {
      dfs(lista[i], 1);
      cnt++;
    }
  }
  long long res = 1;
  long long cost = 0;
  for (int i = 0; i < cnt; i++) {
    long long minval = 2000000000;
    int maxcnt = 0;
    for (int j = 0; j < comp[i].size(); j++) {
      if (prices[comp[i][j]] == minval)
        maxcnt++;
      else if (prices[comp[i][j]] < minval) {
        minval = prices[comp[i][j]];
        maxcnt = 1;
      }
    }
    res = (res * maxcnt) % MOD;
    cost += minval;
  }
  cout << cost << " " << res << endl;
  return 0;
}
