#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m;
int cst[maxn];
int ccc;
multiset<int> cc[maxn];
vector<int> g[maxn], rg[maxn];
int vis[maxn];
vector<pair<int, int> > TT;
int T;
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < (int)g[u].size(); i++) {
    int v = g[u][i];
    if (!vis[v]) {
      dfs(v);
    }
  }
  TT.push_back(make_pair(T++, u));
}
void rdfs(int u) {
  vis[u] = 1;
  cc[ccc].insert(cst[u]);
  for (int i = 0; i < (int)rg[u].size(); i++) {
    int v = rg[u][i];
    if (!vis[v]) {
      rdfs(v);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", cst + i);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    rg[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
  }
  memset(vis, 0, sizeof vis);
  sort(TT.begin(), TT.end());
  reverse(TT.begin(), TT.end());
  for (int i = 0; i < n; i++) {
    int u = TT[i].second;
    if (!vis[u]) {
      rdfs(u);
      ccc++;
    }
  }
  long long ans1 = 0, ans2 = 1;
  int mod = 1e9 + 7;
  for (int i = 0; i < ccc; i++) {
    ans1 += *cc[i].begin();
    ans2 = (1LL * ans2 * cc[i].count(*cc[i].begin())) % mod;
  }
  printf("%I64d %I64d\n", ans1, ans2);
  return 0;
}
