编程介的小学生 2017-08-23 05:38 采纳率: 0.2%
浏览 783
已采纳

Sticker

"Shock You", a name of candy, which is new product of cc98. In fact, its selling point is the sticker inside. To collect different stickers, little children will buy it again and again.

The employees in cc98 are excellent. They have designed 3 kinds of stickers like this, this and this.

picture
But the manager thinks that it is not enough. To persuade his employees, He investigated the habits of some children about collecting.

In this district, a child called WuKe buys one bag of candies every day and gets one sticker inside. So in N days he can get N stickers. If cc98 has N kinds of stickers, he can collect all at least in N day. Unfortunately, it is nearly impossible because of duplicate ones.

But WuKe is not fool. Though duplicate ones are worthless to himself, he can exchange different stickers with others. There are M collectors in the district. To avoid unfair competition, these collectors need different stickers and what they offer are different too. That means, Wuke have to exchange some stickers indirectly.

As we know, if WuKe buys one candy every day, it is usually difficult to collect all N kinds of stickers in N days. But by exchanging, it becomes much easier.

Now the manager of cc98 wants to know how many different ways WuKe can do it.

Note: Different order is regarded as different ways. For instance, if N = 2 and WuKe can exchange 0 to 1, there are 3 ways. (0 0, 0 1 and 1 0)

Input

The first line is an integer C. Then C cases follow. There are no more than 100 cases.

For each case, the first line contains 2 integers N and M (1 ≤ M < N ≤200. Then there are M lines. Each line has 2 integer ai and bi (0 ≤ ai,bi < N), which means there is a collector want to exchange his/her sticker bi to your sticker ai.

Output

A single line contains an integer O indicates how many different ways. It may very large so that you can output O mod 1000000007.

Simple Input

2
2 1
0 1
5 3
0 1
1 2
3 4
Simple Output

3
480

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历