#include <bits/stdc++.h>
using namespace std;
struct Side {
  int st, en;
  bool operator<(const Side& b) const { return st < b.st; }
} side[300005], revside[300005];
int n, m;
int st[100005], en[100005];
int revst[100005], reven[100005];
int val[100005];
int vis[100005], sccno[100005], scc_count;
int save[200005];
int savecount = 0;
void dfs1(int n) {
  if (vis[n]) return;
  vis[n] = 1;
  for (int i = st[n]; i <= en[n]; i++) dfs1(side[i].en);
  save[savecount++] = n;
}
void dfs2(int n) {
  if (sccno[n]) return;
  sccno[n] = scc_count;
  for (int i = revst[n]; i <= reven[n]; i++) dfs2(revside[i].en);
}
void find_scc(int n) {
  scc_count = 0;
  savecount = 0;
  memset(sccno, 0, sizeof(sccno));
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) dfs1(i);
  for (int i = savecount - 1; i >= 0; i--)
    if (!sccno[save[i]]) {
      scc_count++;
      dfs2(save[i]);
    }
}
int minval[100005];
int scount[100005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &val[i]);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &side[i].st, &side[i].en);
    revside[i].st = side[i].en;
    revside[i].en = side[i].st;
  }
  sort(side, side + m);
  sort(revside, revside + m);
  memset(en, -1, sizeof(en));
  memset(reven, -1, sizeof(reven));
  for (int i = 1; i < m; i++)
    if (side[i].st != side[i - 1].st) {
      en[side[i - 1].st] = i - 1;
      st[side[i].st] = i;
    }
  en[side[m - 1].st] = m - 1;
  for (int i = 1; i < m; i++)
    if (revside[i].st != revside[i - 1].st) {
      reven[revside[i - 1].st] = i - 1;
      revst[revside[i].st] = i;
    }
  reven[revside[m - 1].st] = m - 1;
  find_scc(n);
  fill(minval, minval + 100005, INT_MAX);
  fill(scount, scount + 100005, 1);
  for (int i = 1; i <= n; i++)
    if (minval[sccno[i]] > val[i]) {
      minval[sccno[i]] = val[i];
      scount[sccno[i]] = 1;
    } else if (minval[sccno[i]] == val[i]) {
      scount[sccno[i]]++;
    }
  long long ansa = 0, ansb = 1;
  for (int i = 1; i <= scc_count; i++) {
    ansa = ansa + minval[i];
    ansb = (ansb * scount[i]) % 1000000007;
  }
  printf("%I64d %I64d\n", ansa, ansb % 1000000007);
  return 0;
}
