N = int(eval(input()))

edge = [[] for _ in range(N)]

for i in range(N-1):

    a,b = list(map(int, input().split()))

    edge[a-1].append(b-1)

    edge[b-1].append(a-1)



import sys

sys.setrecursionlimit(10**8)



mod = 10**9+7

def dfs(v):

    white,black = 1,1

    for u in edge[v]:

        if visited[u]==False:

            visited[u]=True

            w,b = dfs(u)

            white *= w+b

            white %= mod

            black *= w

            black %= mod

    return white,black



visited = [False]*N

visited[0]=True

print((sum(dfs(0))%mod))
import sys

sys.setrecursionlimit(10**8)



N = int(eval(input()))

edge = [[] for _ in range(N)]

for i in range(N-1):

  a,b = list(map(int, input().split()))

  edge[a-1].append(b-1)

  edge[b-1].append(a-1)



def dfs(v,mod):

  black,white = 1,1

  for u in edge[v]:

    if visited[u]==False:

      visited[u]=True

      b,w = dfs(u,mod)

      black *= w

      white *= b+w

  black %= mod

  white %= mod

  return black,white



mod = 10**9+7

visited = [False]*N

visited[0]=True

black,white = dfs(0,mod)

print(((black+white)%mod))
N = int(eval(input()))
edge = [[] for _ in range(N)]
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)
import sys

sys.setrecursionlimit(10**8)
mod = 10**9 + 7


def dfs(v):
    white, black = 1, 1
    for u in edge[v]:
        if visited[u] == False:
            visited[u] = True
            w, b = dfs(u)
            white *= w + b
            white %= mod
            black *= w
            black %= mod
    return white, black


visited = [False] * N
visited[0] = True
print((sum(dfs(0)) % mod))

import sys

sys.setrecursionlimit(10**8)
N = int(eval(input()))
edge = [[] for _ in range(N)]
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)


def dfs(v, mod):
    black, white = 1, 1
    for u in edge[v]:
        if visited[u] == False:
            visited[u] = True
            b, w = dfs(u, mod)
            black *= w
            white *= b + w
    black %= mod
    white %= mod
    return black, white


mod = 10**9 + 7
visited = [False] * N
visited[0] = True
black, white = dfs(0, mod)
print(((black + white) % mod))

+import sys + +sys.setrecursionlimit(10**8) -import sys - -sys.setrecursionlimit(10**8) -mod = 10**9 + 7 -def dfs(v): -    white, black = 1, 1 +def dfs(v, mod): +    black, white = 1, 1 -            w, b = dfs(u) -            white *= w + b -            white %= mod +            b, w = dfs(u, mod) -            black %= mod -    return white, black +            white *= b + w +    black %= mod +    white %= mod +    return black, white +mod = 10**9 + 7 -print((sum(dfs(0)) % mod)) +black, white = dfs(0, mod) +print(((black + white) % mod))