P20613 [HackerEarth] Munnabhai desires to become a very famous doctor. So he just enrolled in a famous university.
普及
题目描述

Munnabhai desires to become a very famous doctor. So he just enrolled in a famous university.
University offers N different courses. Munnabhai being very passionate towards his studies, wants to study maximum no. of subjects possible. But his college has a weird dependency systems. If he wants to study a course Y, he must need to complete some other course(s) X. Due to the faulty dependency system he is not able to study some of the courses.

Assume he studies only one subject at a time. Each of N courses have a unique code from 1 to N. Given the dependency system of the institute, find the number of courses he could study.

INPUT :
First line contains T - No. of test cases.
For each test case, first line contains two space separated integers N and M , no. of courses and no. of dependencies respectively.
Next M line contains space separated integers X and Y , where course X is prerequisite of course Y.

OUTPUT :
Print maximum possible subjects that Munnabhai can study.

CONSTRAINTS :
1 ≤ T ≤ 10^3
1 ≤ N ≤ 10^3
1 ≤ X , Y ≤ N
0 ≤ M ≤ 2*N
X ≠ Y

Problem Setter : Rajan Kasodariya

SAMPLE INPUT
1
5 6
1 2
1 3
2 4
3 4
4 5
5 4

SAMPLE OUTPUT
3

Explanation

He can study 1 , 2 and 3 courses. but as 4 and 5 are dependent on each other he is not able to study that subjects. So ans is 3

输入格式

见题面

输出格式

见题面

样例输入
4 2 0 5 5 1 2 2 3 3 4 4 5 5 1 2 2 1 2 2 1 5 1 1 2
样例输出
143 405 614 107 575 358 574 168 285 381 154 385 2 490 233 354 587 845 312 145 259 89 358 266 528 835 662 191 248 148 873 97 561 41 125 298 982 51 335 656 935 280 196 17 294 73 42 133 30 162 525 495 320 17 318 768 113 643 192 738 960 214 194 443 475 902 180 337 346 109 115 156 952 660 774 568 128 410 235 93 411 212 323 243 57 87 249 184 36 362 42 253 365 188 608 173 58 257 92 517 499 25 436 473 102 322 810 224 515 178 76 430 811 424 235 18 198 914 35 598 282 699 800 306 245 331 474 873 374 62 801 99 203 286 312 706 196 4 263 71 163 782 380 247 744 346 897 697 705 594 563 316 762 255 438 93 365 74 568 460 132 487 206 1000 410 124 831 931 14 509 285 132 269 119 321 114 95 104 215 442 90 70 889 874 820 123 525 687 802 441 193 704 452 457 728 126 363 293 339 342 85 258 205 217 848 804 230 81 56 754 323 806 844 104 533 813 667 10 767 160 24 978 133 62 61 203 587 314 300 69 29 410 193 107 263 85 205 249 682 406 433 948 221 732 527 176 6 14 334 174 300 62 424 44 138 726 175 103 280 29 348 35 13 136 78 196 193 557 903 550 726 836 130 92 232 492 735 826 138 313 967 310 147 545 209 612 66 40 695 121 192 36 707 832 710 144 641 644 427 211 147 872 62 158 813 283 12 231 228 29 898 491 109 344 204 503 218 937 802 237 131 228 719 161 133 68 233 102 97 112 209 271 65 352 420 484 237 151 19 993 857 396 125 114 334 341 150 821 299 413 190 231 897 249 113 604 228 501 259 692 480 960 607 296 439 960 965 93 116 678 968 76 180 61 168 105 102 721 298 934 127 546 600 561 289 353 92 4 218 138 384 484 155 162 42 766 779 569 253 184 22 708 479 765 213 906 657 170 930 222 977 473 124 785 519 181 767 551 27 165 148 235 222 530 521 56 3 326 346 85 878 865 122 172 370 580 285 320 648 224 67 17 95 402 860 776 679 9 167 198 258 114 400 520 333 382 37 52 228 156 638 585 133 699 163 197 397 351 728 509 304 85 116 478 241 252 268 338 102 323 194 833 999 723 87 147 351 110 181 47 172 274 401 535 171 925 73 361 908 819 115 457 665 199 502 0 9 11 285 868 580 241 337 365 20 229 607 274 223 362 61 27 10 142 141 118 503 423 958 7 120 78 480 89 194 15 527 171 392 52 672 153 418 410 790 39 278 202 224 728 172 330 62 165 158 461 597 77 370 1000 755 830 324 809 226 521 599 396 152 87 54 14 54 533 8 439 513 54 134 11 558 116 506 22 332 234 452 195 248 576 789 80 330 156 460 255 43 505 49 911 53 976 1 121 256 150 383 267 985 373 311 45 204 198 81 133 406 553 609 78 107 9 141 825 410 507 49 547 180 263 541 101 173 992 886 809 380 370 218 23 167 250 72 318 151 782 92 103 947 726 235 414 796 92 72 90 91 245 239 68 194 769 47 644 16 87 119 635 289 933 111 225 529 119 39 413 141 251 95 22 44 993 637 544 104 217 214 475 417 666 459 768 751 479 881 119 268 528 354 927 763 480 316 169 177 293 254 941 44 567 61 673 299 292 331 749 167 817 225 939 210 331 47 432 567 150 170 210 820 675 73 833 352 106 115 79 285 184 800 749 226 1 798 8 10 531 893 84 3 317 310 941 596 14 112 52 213 809 413 325 68 165 632 603 290 497 368 304 939 771 495 339 13 747 82 875 788 190 298 66 422 532 140 528 340 886 618 886 71 560 375 139 77 950 745 701 129 315 892 238 18 912 487 108 75 227 267 313 53 626 629 441 504 967 423 136 746 439 198 897 257 837 238 206 221 828 736 35 846 48 740 189 797 544 152 984 90 196 341 92 62 533 886 688 389 261 191 130 80 824 73 248 983 691 78 119 127 71 99 861 824 460 704 407 360 898 378 102 372 301 204 316 206 17 228 968 442 388 277 347 865 451 48 348 192 943 156 313 560 296 107 30 41 809 763 42 973 922 314 739 750 493 415 223 234 208 585 326 25 4 379 519 376 761 327 179 261 291 68 386 463 168 92 668 381 851 90 384 79 183 65 770 303 96 755 121 790 73 456 100 118 465 35 539 142 152 92 174 34 433 187 197 367 726 392 420 50 866 135 46 0 50 198 411 223 67 889 625 561 287 928 699 596 855 650 144 76 186 471 585 740 434 191 404 176 397 396 422 191 76 29 885 739 952 911 11 8 601 496 833