#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const int mod = 1e9 + 7;
int n, rt, k, ans;
vector<int> edge[maxn], son[maxn];
int dp[maxn], sz[maxn], tot[maxn], len[maxn], nxt[maxn], dfn[maxn], pos[maxn];
void Add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
void prep1(int x, int p) {
  tot[x] = 1;
  for (int i = 0; i < int(edge[x].size()); i++) {
    int y = edge[x][i];
    if (y == p) continue;
    prep1(y, x);
    tot[x] += tot[y];
    son[x].push_back(y);
  }
  sz[x] = int(son[x].size());
  if (!sz[x])
    nxt[x] = 0, len[x] = 1;
  else if (sz[x] == 1)
    nxt[x] = nxt[son[x][0]], len[x] = len[son[x][0]] + 1;
  else
    nxt[x] = x, len[x] = 0;
}
void prep2(int x) {
  dfn[++k] = x;
  pos[x] = k;
  if (sz[x] == 1) {
    prep2(son[x][0]);
    return;
  }
  for (int i = 0; i < sz[x]; i++) prep2(son[x][i]);
}
int jump(int x, int d) { return dfn[pos[x] + d]; }
int subsolve(int x, int y);
int solve(int x) {
  int &res = dp[x];
  if (~res) return res;
  if (tot[x] & 1) return res = 0;
  if (!nxt[x]) return res = tot[x] / 2;
  res = 0;
  if (sz[x] == 1) {
    if (sz[son[x][0]] == 1) Add(res, solve(son[son[x][0]][0]));
    int w = nxt[x];
    for (int f = 0; f < 2; f++) {
      int u = son[w][f], v = son[w][f ^ 1];
      if (sz[u] <= 1) {
        if (nxt[u] == 0 && len[u] == len[x] + 1) Add(res, solve(v));
        if (nxt[u] == 0 && len[u] == len[x] - 1) Add(res, solve(v));
      } else {
        if (nxt[son[u][0]] == 0 && len[son[u][0]] == len[x])
          Add(res, subsolve(v, son[u][1]));
        if (nxt[son[u][1]] == 0 && len[son[u][1]] == len[x])
          Add(res, subsolve(v, son[u][0]));
      }
    }
  } else {
    for (int f = 0; f < 2; f++) {
      int u = son[x][f], v = son[x][f ^ 1];
      if (tot[u] == 1)
        Add(res, solve(v));
      else if (sz[u] == 1)
        Add(res, subsolve(v, son[u][0]));
    }
  }
  return res;
}
int subsolve(int x, int y) {
  if (nxt[x] && nxt[y]) return 0;
  if (len[x] > len[y] || (len[x] == len[y] && nxt[x])) swap(x, y);
  if (nxt[x])
    return 0;
  else if (!nxt[y] && len[x] == len[y])
    return 1;
  else
    return solve(jump(y, len[x]));
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 2 * n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  if (n == 1) {
    puts("2");
    return 0;
  }
  for (int i = 1; i <= 2 * n; i++)
    if (int(edge[i].size()) > int(edge[rt].size())) rt = i;
  if (int(edge[rt].size()) <= 2) {
    printf("%d\n", (2LL * n * n - 2LL * n + 4) % mod);
    return 0;
  }
  if (int(edge[rt].size()) > 3) {
    puts("0");
    return 0;
  }
  prep1(rt, 0);
  prep2(rt);
  for (int i = 1; i <= 2 * n; i++) dp[i] = -1;
  sort(son[rt].begin(), son[rt].end());
  do {
    int x = son[rt][1];
    if (sz[x] == 0)
      Add(ans, 1LL * solve(son[rt][0]) * solve(son[rt][2]) % mod);
    else if (sz[x] == 1) {
      Add(ans, 1LL * subsolve(son[rt][0], son[x][0]) * solve(son[rt][2]) % mod);
      Add(ans, 1LL * solve(son[rt][0]) * subsolve(son[rt][2], son[x][0]) % mod);
    } else {
      Add(ans, 1LL * subsolve(son[rt][0], son[x][0]) *
                   subsolve(son[rt][2], son[x][1]) % mod);
      Add(ans, 1LL * subsolve(son[rt][0], son[x][1]) *
                   subsolve(son[rt][2], son[x][0]) % mod);
    }
  } while (next_permutation(son[rt].begin(), son[rt].end()));
  printf("%d\n", int(2LL * ans % mod));
  return 0;
}
