#include <bits/stdc++.h>
using namespace std;
const int M = 600500;
const int mod = 1000000007;
int dfn[M], vis[M], low[M], ind;
int fa[M], ti, c[M], mini[M][2];
int n, m;
long long int ans = 1, sum = 0;
vector<int> v[M];
stack<int> s;
void tarjan(int x) {
  low[x] = dfn[x] = ++ind;
  vis[x] = 1;
  s.push(x);
  for (int i = 0; i < v[x].size(); i++) {
    int go = v[x][i];
    if (!dfn[go]) {
      tarjan(go);
      low[x] = min(low[x], low[go]);
    } else if (vis[go])
      low[x] = min(low[x], dfn[go]);
  }
  if (low[x] == dfn[x]) {
    int t = -1;
    ti++;
    while (t != x) {
      t = s.top();
      s.pop();
      vis[t] = 0;
      fa[t] = ti;
    }
  }
  return;
}
int main() {
  scanf("%d", &n);
  int a, b;
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b);
    v[a].push_back(b);
  }
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) tarjan(i);
  memset(mini, 0x3f, sizeof(mini));
  for (int i = 1; i <= n; i++)
    if (c[i] < mini[fa[i]][0])
      mini[fa[i]][0] = c[i], mini[fa[i]][1] = 1;
    else if (c[i] == mini[fa[i]][0])
      mini[fa[i]][1]++;
  for (int i = 1; i <= ti; i++)
    ans = (ans * mini[i][1]) % mod, sum += mini[i][0];
  cout << sum << " " << ans % mod;
  return 0;
}
