#include <bits/stdc++.h>
using namespace std;
long long int top = -1;
long long int stackk[500005];
long long int arr[500005];
long long int countt = 1;
long long int summ = 0;
long long int mini;
long long int brr[500005];
long long int indexx = 0;
class Graph {
 private:
  long long int V;
  list<long long int> *array;

 public:
  Graph(long long int V) {
    this->V = V;
    array = new list<long long int>[V + 1];
  }
  void addEdge(long long int u, long long int w) { array[u].push_back(w); }
  void DFSUtil(long long int v, bool visited[]) {
    visited[v] = true;
    list<long long int>::iterator i;
    for (i = array[v].begin(); i != array[v].end(); ++i) {
      if (!visited[*i]) DFSUtil(*i, visited);
    }
    stackk[++top] = v;
  }
  void dfs() {
    bool *visited = new bool[V + 1];
    for (long long int i = 1; i <= V; i++) visited[i] = false;
    for (long long int i = 1; i <= V; i++)
      if (visited[i] == false) DFSUtil(i, visited);
  }
};
class Graphh {
 private:
  long long int VE;
  list<long long int> *brray;

 public:
  Graphh(long long int VE) {
    this->VE = VE;
    brray = new list<long long int>[VE + 1];
  }
  void addEdge(long long int u, long long int w) { brray[u].push_back(w); }
  void DFSUtil(long long int v, long long int visited[]) {
    visited[v] = 1;
    brr[indexx] = v;
    indexx++;
    list<long long int>::iterator i;
    for (i = brray[v].begin(); i != brray[v].end(); ++i) {
      if (!visited[*i]) {
        if (arr[*i] < mini) mini = arr[*i];
        DFSUtil(*i, visited);
      }
    }
  }
};
int main() {
  long long int n;
  cin >> n;
  long long int i;
  for (i = 1; i <= n; i++) scanf("%lld", &arr[i]);
  Graph gh(n);
  long long int m;
  cin >> m;
  Graphh gr(n);
  for (i = 0; i < m; i++) {
    long long int aa, bb;
    cin >> aa >> bb;
    gh.addEdge(aa, bb);
    gr.addEdge(bb, aa);
  }
  gh.dfs();
  long long int visited[n + 1];
  for (i = 1; i <= n; i++) visited[i] = 0;
  while (top != -1) {
    long long int v = stackk[top];
    top--;
    if (visited[v] == 0) {
      long long int mini = 100000000000;
      gr.DFSUtil(v, visited);
      long long int counttt = 1;
      for (i = 0; i < indexx; i++) {
        if (arr[brr[i]] < mini) {
          mini = arr[brr[i]];
          counttt = 1;
        } else if (mini == arr[brr[i]]) {
          counttt++;
        }
      }
      indexx = 0;
      summ += mini;
      countt = (countt * counttt) % 1000000007;
    }
  }
  printf("%lld %lld\n", summ, countt);
}
