#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007, M = 1e5 + 7;
long long powe(long long x, long long y) {
  x = x % mod;
  long long ans = 1;
  while (y > 0) {
    if (y & 1) {
      ans = (1ll * x * ans) % mod;
    }
    y >>= 1;
    x = (1ll * x * x) % mod;
  }
  return ans;
}
vector<vector<int> > edg(M), redg(M);
vector<int> ord, comp;
bool visited[M];
void dfs(int i) {
  visited[i] = true;
  for (auto x : edg[i]) {
    if (!visited[x]) dfs(x);
  }
  ord.push_back(i);
}
void dfs1(int i) {
  comp.push_back(i);
  visited[i] = true;
  for (auto x : redg[i]) {
    if (!visited[x]) dfs1(x);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  long long minc = 0, ways = 1, tmin, ctr;
  cin >> n;
  int cost[n];
  for (int i = 0; i < n; i++) cin >> cost[i];
  int m, a, b;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--, b--;
    edg[a].push_back(b);
    redg[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    if (!visited[i]) dfs(i);
  }
  memset(visited, 0, sizeof(visited));
  for (int i = n - 1; i >= 0; i--) {
    if (!visited[ord[i]]) {
      dfs1(ord[i]);
      tmin = INT_MAX, ctr = 0;
      for (auto x : comp) {
        if (cost[x] < tmin)
          tmin = cost[x], ctr = 1;
        else if (cost[x] == tmin)
          ctr++;
      }
      comp.clear();
      minc += tmin;
      ways = (ways * ctr) % mod;
    }
  }
  cout << minc << " " << ways;
  return 0;
}
