#include <bits/stdc++.h>
using namespace std;
int64_t N, M;
vector<int64_t> Edge[300007];
bool Visit[300007];
bool InStk[300007];
int64_t Low[300007], I;
int64_t Ind[300007];
int costs[300007];
stack<int64_t> Stk;
int64_t mincost;
int64_t possib;
void SCC(int64_t u) {
  Visit[u] = true;
  InStk[u] = true;
  Ind[u] = ++I;
  Low[u] = I;
  Stk.push(u);
  int64_t i;
  for (i = 0; i < Edge[u].size(); i++) {
    int64_t v = Edge[u][i];
    if (!Visit[v]) {
      SCC(v);
      Low[u] = min(Low[u], Low[v]);
    } else if (InStk[v]) {
      Low[u] = min(Low[u], Ind[v]);
    }
  }
  if (Low[u] != Ind[u]) return;
  int64_t minc = 1000000000;
  int64_t mintime = 0;
  while (Stk.top() != u) {
    int64_t v = Stk.top();
    Stk.pop();
    InStk[v] = false;
    if (costs[v] < minc) {
      minc = costs[v];
      mintime = 1;
    } else if (costs[v] == minc) {
      mintime++;
    }
  }
  if (costs[u] < minc) {
    minc = costs[u];
    mintime = 1;
  } else if (costs[u] == minc) {
    mintime++;
  }
  mincost += minc;
  possib = (possib * mintime) % 1000000007;
  Stk.pop();
  InStk[u] = false;
}
int main(void) {
  int64_t i, j, u, v, Icase, k = 0;
  mincost = 0;
  possib = 1;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> costs[i + 1];
  }
  cin >> M;
  for (i = 1; i <= M; i++) {
    cin >> u >> v;
    Edge[u].push_back(v);
  }
  for (i = 1; i <= N; i++) {
    if (Visit[i]) continue;
    SCC(i);
  }
  cout << mincost << " " << possib;
  return 0;
}
