#include <bits/stdc++.h>
using namespace std;
struct node {
  long long to, next;
} e[400100];
long long siz[400100], g1[400100], p[400100], l[400100], r[400100], mem[400100],
    dp[400100], len[400100], size, o, w, n, i, du[400100], ro[5], root, ans;
void add(long long o, long long p) {
  e[++size].to = p, e[size].next = g1[o];
  g1[o] = size;
}
void dfs(long long x, long long fa) {
  siz[x] = 1;
  for (long long k = g1[x]; k; k = e[k].next) {
    long long y = e[k].to;
    if (y != fa) {
      dfs(y, x);
      siz[x] += siz[y];
      if (l[x] == 0)
        l[x] = y, len[x] = len[y] + 1, p[x] = p[y];
      else
        r[x] = y;
    }
  }
  if (r[x]) p[x] = x, len[x] = 0;
}
long long f(long long);
long long g(long long, long long);
long long solve(long long o, long long x, long long y) {
  long long ret = 0;
  if (r[y] == 0) {
    if (len[o] % 2 == 0 && siz[y] > 1) (ret += g(l[y], x)) %= 1000000007;
    if (!p[y] && len[y] <= len[o] && (len[y] + len[o]) % 2 == 0)
      (ret += f(x) * (len[o] - len[y] >= 2 ? 2 : 1)) %= 1000000007;
  } else {
    if (!p[l[y]] && len[l[y]] + 1 <= len[o] &&
        (len[l[y]] + 1 + len[o]) % 2 == 0)
      (ret += g(x, r[y])) %= 1000000007;
    if (!p[r[y]] && len[r[y]] + 1 <= len[o] &&
        (len[r[y]] + 1 + len[o]) % 2 == 0)
      (ret += g(x, l[y])) %= 1000000007;
  }
  return ret;
}
long long f(long long o) {
  if (o == 0) return 1;
  if (siz[o] & 1) return 0;
  if (mem[o] == 1) return dp[o];
  if (p[o] == 0) return siz[o] / 2;
  long long ret = 0;
  (ret += solve(o, r[p[o]], l[p[o]])) %= 1000000007;
  (ret += solve(o, l[p[o]], r[p[o]])) %= 1000000007;
  mem[o] = 1, dp[o] = ret;
  return ret;
}
long long g(long long x, long long y) {
  if (x == 0 || y == 0) return f(x + y);
  if (r[x] || r[y]) return 0;
  return g(l[x], l[y]);
}
int main() {
  scanf("%lld", &n);
  n *= 2;
  for (i = 1; i < n; i++) {
    scanf("%lld %lld", &o, &w);
    add(o, w), add(w, o);
    du[o]++, du[w]++;
  }
  long long root = max_element(du + 1, du + 1 + n) - du;
  if (du[root] > 3) {
    printf("0\n");
    return 0;
  }
  if (du[root] == 1) {
    printf("2\n");
    return 0;
  }
  if (du[root] == 2) {
    n /= 2, printf("%lld\n", (2ll * n * n - 2ll * n + 4) % 1000000007);
    return 0;
  }
  long long rotmp = 0;
  for (long long k = g1[root]; k; k = e[k].next) ro[++rotmp] = e[k].to;
  dfs(root, -1);
  for (long long o = 1; o <= 3; o++)
    for (long long p = 1; p <= 3; p++)
      if (o != p) {
        long long q = 6 - o - p;
        long long x = ro[o], y = ro[p], z = ro[q];
        if (l[z] == 0)
          (ans += f(x) * f(y)) %= 1000000007;
        else if (r[z] == 0)
          (ans += g(l[z], x) * f(y)) %= 1000000007,
              (ans += g(l[z], y) * f(x)) %= 1000000007;
        else
          (ans += g(l[z], x) * g(r[z], y)) %= 1000000007,
              (ans += g(l[z], y) * g(r[z], x)) %= 1000000007;
      }
  printf("%lld\n", ans * 2 % 1000000007);
}
