#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100010], adjr[100010];
long long arr[100010], visited[100010], visited2[100010], mi, coun;
stack<long long> ss;
void dfs(long long so, long long pa) {
  long long i, xx, h = adj[so].size();
  visited[so] = 1;
  for (i = 0; i <= h - 1; i++) {
    xx = adj[so][i];
    if ((xx == pa) || (visited[xx] == 1)) {
      continue;
    } else {
      dfs(xx, so);
    }
  }
  ss.push(so);
}
void dfs2(long long so, long long pa) {
  if (mi > arr[so]) {
    mi = arr[so];
    coun = 1;
  } else if (mi == arr[so]) {
    coun++;
  }
  visited2[so] = 1;
  long long i, xx, h = adjr[so].size();
  for (i = 0; i <= h - 1; i++) {
    xx = adjr[so][i];
    if ((xx == pa) || (visited2[xx] == 1)) {
      continue;
    } else if (visited[xx] == 1) {
      dfs2(xx, so);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long N, i, M, U, V, j, flag, uu, cost = 0, way = 1;
  cin >> N;
  for (i = 0; i <= N - 1; i++) {
    cin >> arr[i];
  }
  cin >> M;
  for (i = 0; i <= M - 1; i++) {
    cin >> U >> V;
    U--;
    V--;
    adj[U].push_back(V);
    adjr[V].push_back(U);
  }
  long long ind = 0;
  while (1) {
    flag = 0;
    for (i = ind; i <= N - 1; i++) {
      if (visited[i] == 0) {
        flag = 1;
        break;
      }
    }
    ind = (i + 1);
    if (flag == 1) {
      dfs(i, -1);
      while (!ss.empty()) {
        uu = ss.top();
        ss.pop();
        mi = INT_MAX;
        coun = 0;
        if (visited2[uu] == 0) {
          dfs2(uu, -1);
        }
        if (mi != INT_MAX) {
          cost += mi;
          way = ((way * coun) % 1000000007);
        }
      }
    } else {
      break;
    }
  }
  cout << cost << " " << way;
  return 0;
}
