#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1.0);
int cs = 1, test;
int price[100009];
vector<int> edge[100009];
int dfsnum[100009], dfslow[100009], vis[100009];
int counter, numscc;
vector<int> S;
vector<int> comp[100009];
void scc(int u) {
  dfslow[u] = dfsnum[u] = counter++;
  S.push_back(u);
  vis[u] = 1;
  for (int i = 0; i < edge[u].size(); i++) {
    int v = edge[u][i];
    if (vis[v] == 0) scc(v);
    if (vis[v] == 1) dfslow[u] = min(dfslow[u], dfslow[v]);
  }
  if (dfslow[u] == dfsnum[u]) {
    numscc++;
    while (1) {
      int v = S.back();
      S.pop_back();
      vis[v] = 2;
      comp[numscc].push_back(v);
      if (u == v) break;
    }
  }
}
void tarjanscc(int n) {
  memset((dfsnum), 0, sizeof(dfsnum));
  memset((dfslow), 0, sizeof(dfslow));
  memset((vis), 0, sizeof(vis));
  counter = 1;
  numscc = 0;
  for (int i = 1; i <= n; i++)
    if (dfsnum[i] == 0) scc(i);
}
int main() {
  int i, j, k, x, y, z, len, count = 0, mx = -1, q, lineflag = 0;
  int n, m;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &price[i]);
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    edge[x].push_back(y);
  }
  tarjanscc(n);
  long long int ans = 0, way = 1;
  for (i = 1; i <= numscc; i++) {
    long long int cnt = 0, mn = INT_MAX;
    for (j = 0; j < comp[i].size(); j++) {
      int v = comp[i][j];
      if (price[v] < mn) {
        cnt = 1;
        mn = price[v];
      } else if (price[v] == mn)
        cnt++;
    }
    ans += mn;
    way = (way * cnt) % 1000000007;
  }
  printf("%lld %lld\n", ans, way);
  return 0;
}
