#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
struct Edge {
  int from, to, nxt;
} e[400050];
int n, m;
int fir[100050];
long long val[100050];
long long ans[100050] = {0};
long long num[100050], cnt = 0, tim = 0, cc = 0, aa = 0, a2 = 1;
int dfn[100050], belon[100050], low[100050];
bool vis[100050];
stack<int> s;
void add(int from, int to) {
  e[++cnt].from = from;
  e[cnt].to = to;
  e[cnt].nxt = fir[from];
  fir[from] = cnt;
}
void tarjan(int x) {
  low[x] = dfn[x] = ++tim;
  vis[x] = 1;
  s.push(x);
  for (int i = fir[x]; i != -1; i = e[i].nxt) {
    int y = e[i].to;
    if (!dfn[y]) {
      tarjan(y);
      low[x] = min(low[x], low[y]);
    } else if (vis[y]) {
      low[x] = min(low[x], dfn[y]);
    }
  }
  if (low[x] == dfn[x]) {
    cc++;
    int v;
    while (!s.empty()) {
      v = s.top();
      s.pop();
      belon[v] = cc;
      vis[v] = false;
      if (ans[cc] > val[v]) {
        ans[cc] = val[v];
        num[cc] = 1;
      } else if (ans[cc] == val[v]) {
        num[cc]++;
      }
      if (x == v) break;
    }
  }
}
int main() {
  cin >> n;
  memset(ans, 127, sizeof(ans));
  memset(fir, -1, sizeof(fir));
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &val[i]);
  }
  cin >> m;
  int x, y;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    add(x, y);
  }
  for (int i = 1; i <= n; i++) {
    if (!dfn[i]) tarjan(i);
  }
  aa = 0, a2 = 1;
  for (int i = 1; i <= cc; i++) {
    aa = aa + ans[i];
    a2 = (a2 * num[i]) % mod;
  }
  cout << aa << " " << a2;
  return 0;
}
