#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 10, MOD = 1e9 + 7;
int mark[MAXN], color[MAXN], backEdge[MAXN], depth[MAXN];
bool deleted[MAXN];
vector<int> adj[MAXN], stc;
int idx = 0;
void dfs(int x) {
  int mn = idx;
  depth[x] = idx;
  mark[x] = 1;
  stc.push_back(x);
  for (int i = 0; i < ((int)(adj[x]).size()); i++) {
    int v = adj[x][i];
    if (mark[v] == 0) {
      idx++;
      dfs(v);
      mn = min(mn, backEdge[v]);
    } else if (mark[v] == 1)
      mn = min(mn, depth[v]);
    else if (mark[v] == 2 && !deleted[v])
      mn = min(mn, backEdge[v]);
  }
  backEdge[x] = mn;
  if (mn == depth[x]) {
    while (true) {
      color[stc.back()] = x;
      deleted[stc.back()] = true;
      if (stc.back() == x) {
        stc.pop_back();
        break;
      }
      stc.pop_back();
    }
  }
  mark[x] = 2;
}
vector<int> c[MAXN];
int v[MAXN];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < (n); i++) cin >> v[i];
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    adj[x].push_back(y);
  }
  for (int i = 0; i < (n); i++)
    if (!mark[i]) dfs(i);
  for (int i = 0; i < (n); i++) c[color[i]].push_back(v[i]);
  long long ans = 1, cost = 0;
  for (int i = 0; i < (n); i++)
    if (((int)(c[i]).size())) {
      sort((c[i]).begin(), (c[i]).end());
      cost += c[i][0];
      int cur = 0;
      for (int j = 0; j < ((int)(c[i]).size()); j++)
        if (c[i][j] == c[i][0]) cur++;
      ans = (ans * cur) % MOD;
    }
  cout << cost << ' ' << ans << endl;
  return 0;
}
