using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

public class Solver
{
    public void Solve()
    {
        int n = ReadInt();

        for (int i = 0; i < n; i++)
        {
            string line = reader.ReadLine();
            string[] tokens = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            ulong l = ulong.Parse(tokens[0]);
            ulong r = ulong.Parse(tokens[1]);
            ulong d = ulong.Parse(tokens[2]);

            if (d < l)
            {
                Write(d);
            }
            else
            {
                ulong x = r / d;
                if (x == 0)
                {
                    x++;
                }

                if (x * d <= r)
                {
                    x++;
                }
                Write(x * d);
            }
        }
    }

    #region CSharp template by azukun

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
        Stopwatch watch = new Stopwatch();
        watch.Start();
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {

            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();

#if DEBUG
            watch.Stop();
            Write("Stopwatch: " + watch.ElapsedMilliseconds + "ms");
#endif
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
#endregion
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace FirstDemoCSharp
{

    class Program
    {

        static int find(int l, int r, int d)
        {
            if (d < l || d > r) return d;
            return (r / d + 1) * d;
        }

        static void Main(string[] args)
        {

            var q = int.Parse(ReadLine());
            while (q > 0)
            {
                var line = ReadLine().Split();

                var l = int.Parse(line[0]);
                var r = int.Parse(line[1]);
                var d = int.Parse(line[2]);

                WriteLine(find(l, r, d));
                q--;
            }

        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){

		for(int i=0;i<Q;i++){
			if(D[i] < L[i]){
				Console.WriteLine(D[i]);
			} else {
				long rr = R[i] / D[i] * D[i];
				for(;rr<=R[i];rr+=D[i]);
				Console.WriteLine(rr);
			}

		}

	}
	int Q;
	long[] L,R,D;
	public Sol(){
		Q = ri();
		L = new long[Q];
		R = new long[Q];
		D = new long[Q];
		for(int i=0;i<Q;i++){
			var d = rla();
			L[i] = d[0]; R[i] = d[1]; D[i] = d[2];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Баян
{
    class Program
    {
        static void paint(int n, uint[] min, uint[] max, bool[] peres)
        {
            int peresLength = peres.Length;
            for (int i = 0; i < peresLength; i++)
            {
                if (!(min[i] > max[n] || min[n] > max[i]) && !peres[i] && i != n)
                //     if (((min[i] >= min[n] && min[i] <= max[n]) || (max[i] >= min[n] && max[i] <= max[n]) || (min[i] <= min[n] && max[i] >= max[n])) && !peres[i] && i != n)
                {
                    peres[i] = true;
                    paint(i, min, max, peres);
                }
            }
            return;
        }

        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] str;
            int l, r, d, x;
            for (int i = 0; i < n; i++)
            {
                str = Console.ReadLine().Split(' ');
                l = Convert.ToInt32(str[0]);
                r = Convert.ToInt32(str[1]);
                d = Convert.ToInt32(str[2]);
                if (d < l || d > r)
                    Console.WriteLine(d);
                else
                {
                    x = r / d + 1;
                    Console.WriteLine(d * x);
                }
            }

 //     Console.ReadKey();

        }
    }
}


/*
csc -debug A.cs && mono --debug A.exe <<< "5
2 4 2
5 10 4
3 10 1
1 2 3
4 6 5"
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class HelloWorld {
    public static void SolveCodeForces() {
        var t = cin.NextInt();
        while (t-->0) {
            var l = cin.NextLong();
            var r = cin.NextLong();
            var d = cin.NextLong();

            if (d < l)
                System.Console.WriteLine(d);
            else {
                var p = r % d == 0 ? (r + d) : (r / d * d + d);
                System.Console.WriteLine(p);
            }
        }
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // System.Console.Write(cout.ToString());
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }

    public static IEnumerable<int> IndicesWhere<T>(this IEnumerable<T> seq, Func<T, bool> cond) {
        var i = 0;
        foreach (var item in seq) {
            if (cond(item)) yield return i;
            i++;
        }
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var q = ReadInt();
            for (int i = 0; i < q; i++)
            {
                var input = ReadArrayInt();
                var l = input[0];
                var r = input[1];
                var d = input[2];
                if (d < l || d > r) Console.WriteLine(d);
                else Console.WriteLine(r / d * d + d);
            }

            Console.WriteLine();
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var q = ReadInt();
            for (int i = 0; i < q; i++)
            {
                var input = ReadArrayInt();
                var l = input[0];
                var r = input[1];
                var d = input[2];
                var ans = d;
                while (true)
                {
                    if (ans < l || ans > r)
                    {
                        Console.WriteLine(ans);
                        break;
                    }
                    else ans += d;
                }
            }

            Console.WriteLine();
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace пробник
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            for(int i = 0; i<n; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                int l = int.Parse(s[0]);
                int r = int.Parse(s[1]);
                int d = int.Parse(s[2]);
                if(d<l)
                    Console.WriteLine(d);
                else
                    Console.WriteLine(d*(r/d+1));
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;

namespace prA {
    class Program {
#if ONLINE_JUDGE
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
#else
        private static readonly StreamWriter writer = new StreamWriter(@"..\..\output");
        private static readonly StreamReader reader = new StreamReader(@"..\..\input");
#endif

        static void Main(string[] args) {
            int q = NextInt();
            for (int qi = 0; qi < q; qi++) {
                long l = NextInt();
                long r = NextInt();
                long d = NextInt();
                long x = 0;
                if(l > d) {
                    x = d;
                }
                else {
                    x = (r / d + 1) * d;
                    if(x == r)
                        x += d;
                }
                writer.WriteLine(x);
            }

            writer.Flush();
#if !ONLINE_JUDGE
            writer.Close();
#endif
        }
        private static int NextInt() {
            int c;
            int res = 0;
            do {
                c = reader.Read();
                if(c == -1)
                    return res;
            } while(c != '-' && (c < '0' || c > '9'));
            int sign = 1;
            if(c == '-') {
                sign = -1;
                c = reader.Read();
            }
            res = c - '0';
            while(true) {
                c = reader.Read();
                if(c < '0' || c > '9')
                    return res * sign;
                res *= 10;
                res += c - '0';
            }
        }
        private static long NextLong() {
            int c;
            long res = 0;
            do {
                c = reader.Read();
                if(c == -1)
                    return res;
            } while(c != '-' && (c < '0' || c > '9'));
            int sign = 1;
            if(c == '-') {
                sign = -1;
                c = reader.Read();
            }
            res = c - '0';
            while(true) {
                c = reader.Read();
                if(c < '0' || c > '9')
                    return res * sign;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                var parts = Console.ReadLine().Split(' ');
                int l = int.Parse(parts[0]), r = int.Parse(parts[1]), d = int.Parse(parts[2]);

                if (d < l)
                {
                    Console.WriteLine(d);
                }
                else
                {
                    int f = (l-1) / d;
                    if (f > 1)
                    {
                        Console.WriteLine(2 * d);
                    }
                    else
                    {
                        f = r/d + 1;
                        Console.WriteLine(f * d);
                    }
                }
            }
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Policy;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Factorial
{
    class Program
    {
        static void Main(string[] args)
        {
            int q = Convert.ToInt32(Console.ReadLine());
            for (int j = 0; j < q; j++)
            {
                var p = Console.ReadLine().Split();
                long l = Convert.ToInt64(p[0]), r = Convert.ToInt64(p[1]), d = Convert.ToInt64(p[2]);
                long dif = r - l; long i = 1;
                while (i > 0)
                {
                    if (i == l)
                        i += dif + 1;
                    if (i % d == 0) { Console.WriteLine(i); break; }
                    i++;
                }
            }
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Policy;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Factorial
{
    class Program
    {
        static void Main(string[] args)
        {
            int q = Convert.ToInt32(Console.ReadLine());
            for (int j = 0; j < q; j++)
            {
                var p = Console.ReadLine().Split();
                long l = Convert.ToInt64(p[0]), r = Convert.ToInt64(p[1]), d = Convert.ToInt64(p[2]);
                if(d < l || d > r)
                    Console.WriteLine(d);
                else
                    Console.WriteLine(Convert.ToInt64(r/d) * d + d);
            }
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Policy;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Factorial
{
    class Program
    {
        static void Main(string[] args)
        {
            int q = Convert.ToInt32(Console.ReadLine());
            for (int j = 0; j < q; j++)
            {
                var p = Console.ReadLine().Split();
                long l = Convert.ToInt64(p[0]), r = Convert.ToInt64(p[1]), d = Convert.ToInt64(p[2]);
                long dif = r - l; long i = 1; bool t = false;
                while (i < l)
                {
                    if (i % d == 0)
                    { Console.WriteLine(i); t = true; break; }
                    else
                        i += i % d;
                }
                if (t == false)
                {
                    long k = r + 1;
                    if (k % d == 0)
                        Console.WriteLine(k);
                    else Console.WriteLine(k + k % d + 1);
                }
            }
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Policy;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Factorial
{
    class Program
    {
        static void Main(string[] args)
        {
            int q = Convert.ToInt32(Console.ReadLine());
            for (int k = 0; k < q; k++)
            {
                var p = Console.ReadLine().Split();
                int l = Convert.ToInt32(p[0]), r = Convert.ToInt32(p[1]), d = Convert.ToInt32(p[2]);
                int i = 1;
                bool t = false;
                while (i < l)
                    if (i % d == 0) { Console.WriteLine(i); t = true; break; } else i++;
                if (t == false) { int j = r + 1; while (j % d != 0) j++; Console.WriteLine(j); }
            }
        }
    }
}


using System;

namespace min_int
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] input = Console.ReadLine().Split();
            int q = Int32.Parse(input[0]);
            int l;
            int r;
            int d;
            int temp;
            int x;
            for (int i = 0; i < q; i++)
            {
                input = Console.ReadLine().Split();
                l = Int32.Parse(input[0]);
                r = Int32.Parse(input[1]);
                d = Int32.Parse(input[2]);
                x = d;

                if (d < l || d > r)
                    temp = x;
                else
                {
                    while (true)
                    {
                        if (x < l || x > r)
                        {
                            temp = x;
                            break;
                        }
                        x += d;
                    }
                }

                Console.WriteLine(temp);
            }
        }
    }
}


using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            int q = int.Parse(Console.ReadLine());
            long l;
            long r;
            long d;
            long temp;

            for (int i = 0; i < q; i++)
            {
                long[] input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
                l = input[0];
                r = input[1];
                d = input[2];

                if (d < l)
                    temp = d;
                else
                    temp = d * (r / d + 1);

                Console.WriteLine(temp);
            }
        }
    }
}


using System;

namespace min_int
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] input = Console.ReadLine().Split();
            int q = Int32.Parse(input[0]);
            int l;
            int r;
            int d;
            int temp;
            int x;
            for (int i = 0; i < q; i++)
            {
                input = Console.ReadLine().Split();
                l = Int32.Parse(input[0]);
                r = Int32.Parse(input[1]);
                d = Int32.Parse(input[2]);
                x = d;
                while (true)
                {
                    if (x < l || x > r)
                    {
                        temp = x;
                        break;
                    }
                    x += d;
                }

                Console.WriteLine(temp);
            }
        }
    }
}


using System;

namespace min_int
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] input = Console.ReadLine().Split();
            int q = Int32.Parse(input[0]);
            int l;
            int r;
            int d;
            int temp;
            int x;
            for (int i = 0; i < q; i++)
            {
                input = Console.ReadLine().Split();
                l = Int32.Parse(input[0]);
                r = Int32.Parse(input[1]);
                d = Int32.Parse(input[2]);
                x = d;

                if (d < l || d > r)
                    temp = x;
                else
                {
                    while (x < r)
                        x += d;
                    temp = x;
                }

                Console.WriteLine(temp);
            }
        }
    }
}


using System;

namespace min_int
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] input = Console.ReadLine().Split();
            int q = Int32.Parse(input[0]);
            int l;
            int r;
            int d;
            int temp;
            int x;
            for (int i = 0; i < q; i++)
            {
                input = Console.ReadLine().Split();
                l = Int32.Parse(input[0]);
                r = Int32.Parse(input[1]);
                d = Int32.Parse(input[2]);
                x = d;

                if (d < l || d > r)
                    temp = x;
                else
                {
                    while (x <= r)
                        x += d;
                    temp = x;
                }

                Console.WriteLine(temp);
            }
        }
    }
}


using System;

namespace min_int
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] input = Console.ReadLine().Split();
            int q = Int32.Parse(input[0]);
            int l;
            int r;
            int d;
            int temp;
            int x;
            for (int i = 0; i < q; i++)
            {
                input = Console.ReadLine().Split();
                l = Int32.Parse(input[0]);
                r = Int32.Parse(input[1]);
                d = Int32.Parse(input[2]);
                x = 1;
                while (true)
                {
                    if (x % d == 0 && (x < l || x > r))
                    {
                        temp = x;
                        break;
                    }
                    x++;
                }

                Console.WriteLine(temp);
            }
        }
    }
}


using System;
using System.Linq;

namespace CodeForce
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var linesCount = int.Parse(Console.ReadLine());
            for (int i = 0; i < linesCount; i++)
            {
                var numbers = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                var l = numbers[0];
                var r = numbers[1];
                var d = numbers[2];
                if (d < l || d > r) Console.WriteLine(d);
                else if (d > r) Console.WriteLine(d);
                else
                {
                    Console.WriteLine((r + d) - (r % d));
                }
            }
           // Console.ReadKey();
        }
    }
}


using System;
using System.Linq;

namespace CodeForce
{
    public class Program
    {
        static void Main(string[] args)
        {
            foreach (var _ in Enumerable.Range(0, int.Parse(Console.ReadLine()) + 1))
            {
                var numbers = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                for (int i = numbers[2]; true; i += numbers[2])
                {
                    if (i >= numbers[0] && i <= numbers[1]) continue;
                    if (i % numbers[2] == 0)
                    {
                        Console.WriteLine(i);
                        break;
                    }
                }
            }
        }
    }
}


using System;
using System.Linq;

namespace CodeForce
{
    class Program
    {
        static void Main(string[] args)
        {
            foreach (var _ in Enumerable.Range(0, int.Parse(Console.ReadLine()) + 1))
            {
                var numbers = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                for (int i = numbers[2]; true; i += numbers[2])
                {
                    if (i >= numbers[0] && i <= numbers[1]) continue;
                    if (i % numbers[2] == 0)
                    {
                        Console.WriteLine(i);
                        break;
                    }
                }
            }
            Console.ReadKey();
        }
    }
}


using System;
using System.Linq;

namespace CodeForce
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var linesCount = int.Parse(Console.ReadLine());
            for (int i = 0; i < linesCount; i++)
            {
                var numbers = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                for (int j = numbers[2]; true; j++)
                {
                    if (j >= numbers[0] && j <= numbers[1])
                    {
                        j = numbers[1];
                        continue;
                    }
                    if (j % numbers[2] == 0)
                    {
                        Console.WriteLine(j);
                        break;
                    }
                }
            }
        }
    }
}


using System;
using System.Linq;

namespace CodeForce
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var linesCount = int.Parse(Console.ReadLine());
            for (int i = 0; i < linesCount; i++)
            {
                var numbers = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                for (int j = numbers[2]; true; j += numbers[2])
                {
                    if (j >= numbers[0] && j <= numbers[1]) continue;
                    if (j % numbers[2] == 0)
                    {
                        Console.WriteLine(j);
                        break;
                    }
                }
            }
        }
    }
}


using System;
using System.Linq;

namespace CodeForce
{
    class Program
    {
        static void Main(string[] args)
        {
            foreach (var _ in Enumerable.Range(0, int.Parse(Console.ReadLine()) + 1))
            {
                var numbers = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                for (int i = numbers[2]; true; i += numbers[2])
                {
                    if (i >= numbers[0] && i <= numbers[1]) continue;
                    if (i % numbers[2] == 0)
                    {
                        Console.WriteLine(i);
                        break;
                    }
                }
            }
            // Console.ReadKey();
        }
    }
}


using System;
using System.Linq;

namespace CodeForce
{
    public class Program
    {
        public static void Main(string[] args)
        {
            foreach (var _ in Enumerable.Range(0, int.Parse(Console.ReadLine()) + 1))
            {
                var numbers = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                for (int i = numbers[2]; true; i += numbers[2])
                {
                    if (i >= numbers[0] && i <= numbers[1]) continue;
                    if (i % numbers[2] == 0)
                    {
                        Console.WriteLine(i);
                        break;
                    }
                }
            }
        }
    }
}


// Problem: 1101A - Minimum Integer
// Author: Gusztav Szmolik

using System;

class MinimumInteger
    {
    static int Main ()
        {
        string[] words = ReadSplitLine (1);
        if (words == null)
            return -1;
        ushort q;
        if (!UInt16.TryParse (words[0], out q))
            return -1;
        if (q < 1 || q > 500)
            return -1;
        for (ushort i = 0; i < q; i++)
            {
            words = ReadSplitLine (3);
            if (words == null)
                return -1;
            uint l;
            if (!UInt32.TryParse (words[0], out l))
                return -1;
            if (l < 1 || l > 1000000000)
                return -1;
            uint r;
            if (!UInt32.TryParse (words[1], out r))
                return -1;
            if (r < l || l > 1000000000)
                return -1;
            uint d;
            if (!UInt32.TryParse (words[2], out d))
                return -1;
            if (d < 1 || d > 1000000000)
                return -1;
            uint ans = (d < l ? d : r+(d-r%d));
            Console.WriteLine (ans);
            }
        return 0;
        }

    static string[] ReadSplitLine (uint numWordNeed)
        {
        string line = Console.ReadLine ();
        if (line == null)
            return null;
        char[] delims = new char[2] {' ', '\t'};
        string[] words = line.Split (delims,StringSplitOptions.RemoveEmptyEntries);
        return (words.Length == numWordNeed ? words : null);
        }
    }


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Codeforces
{
	class Program
	{
		static void Main(string[] args)
		{
			string input1 = Console.ReadLine();
			//string input2 = Console.ReadLine();
			//string input3 = Console.ReadLine();
			//string input4 = Console.ReadLine();

			//var inputs1 = input1.Split(new[] { ' ', '}', '{' , ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
			//var inputs2 = input2.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();

			int q = int.Parse(input1);

			var results = new List<long>();
			for (int i = 0; i < q; i++)
			{
				var inputs = Console.ReadLine().Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
				long l = inputs[0];
				long r = inputs[1];
				long d = inputs[2];

				double min = (double)l / d;
				double max = (double)r / d;
				if (min > 1)
				{
					results.Add(d);
					continue;
				}

				var temp = (long)Math.Ceiling(max);
				results.Add(d * ((r % d) > 0 ? temp : (temp + 1)));
			}

			foreach (var result in results)
			{
				Console.WriteLine(result);
			}
		}

		private static long NumbersSum(long a)
		{
			long copyA = a, sum = 0;
			while (copyA > 0)
			{
				sum += copyA % 10;
				copyA /= 10;
			}

			return sum;
		}

		private static long GCD(long a, long b)
		{
			long max = Math.Max(a, b);
			long min = Math.Min(a, b);

			if (min == 0)
			{
				return max;
			}
			a = min;
			b = max % min;
			return GCD(a, b);
		}

		private static long LCM(long a, long b)
		{
			return Math.Abs(a * b) / GCD(a, b);
		}

		static long Factorial(long a)
		{
			return a > 1 ? a * Factorial(a - 1) : 1;
		}
	}
}


using System;
using static System.Math;
namespace ConsoleApplication1
{
    internal static class Program
    {
        public static void Main()
        {
            Int64 n = Int64.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                string[] tokens = Console.ReadLine().Split();
                if (Int64.Parse(tokens[1]) % Int64.Parse(tokens[2]) == 0)
                    tokens[1] = (Int64.Parse(tokens[1]) + 1).ToString();
                if (Int64.Parse(tokens[2]) < Int64.Parse(tokens[0]))
                    Console.WriteLine(tokens[2]);
                else
                    Console.WriteLine((Int64.Parse(tokens[1]) + Int64.Parse(tokens[2]) - 1) / Int64.Parse(tokens[2]) * Int64.Parse(tokens[2]));
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace Codeforces
{
	internal class Template
	{
		private List<int>[] adj = new List<int>[150100];
		private bool[] visited;
		private bool[] visited2;

		private void Solve()
		{
			var n = cin.NextInt();
			var m = cin.NextInt();
			for (var i = 1; i <= n; i++)
			{
				adj[i] = new List<int>();
			}
			for (var i = 0; i < m; i++)
			{
				var a = cin.NextInt();
				var b = cin.NextInt();
				adj[a].Add(b);
				adj[b].Add(a);
			}
			visited = new bool[n + 10];
			visited2 = new bool[n + 10];
			for (var i = 1; i <= n; i++)
			{
				if (visited[i])
				{
					continue;
				}
				var count = Dfs(i);
				if (!Dfs2(i, count - 1))
				{
					Console.WriteLine("NO");
					return;
				}
			}
			Console.WriteLine("YES");
		}

		private bool Dfs2(int v, int ad)
		{
			visited2[v] = true;
			if (adj[v].Count != ad)
			{
				return false;
			}
			foreach (var child in adj[v])
			{
				if (!visited2[child])
				{
					if (!Dfs2(child, ad))
					{
						return false;
					}
				}
			}
			return true;
		}

		private int Dfs(int v)
		{
			var count = 1;
			visited[v] = true;
			foreach (var child in adj[v])
			{
				if (!visited[child])
				{
					count += Dfs(child);
				}
			}
			return count;
		}

		private static readonly Scanner cin = new Scanner();

		private static void Main()
		{
#if DEBUG
			var inputText = File.ReadAllText(@"..\..\input.txt");
			var testCases = inputText.Split(new[] { "input" }, StringSplitOptions.RemoveEmptyEntries);
			var consoleOut = Console.Out;
			for (var i = 0; i < testCases.Length; i++)
			{
				var parts = testCases[i].Split(new[] { "output" }, StringSplitOptions.RemoveEmptyEntries);
				Console.SetIn(new StringReader(parts[0].Trim()));
				var stringWriter = new StringWriter();
				Console.SetOut(stringWriter);
				var sw = Stopwatch.StartNew();
				new Template().Solve();
				sw.Stop();
				var output = stringWriter.ToString();

				Console.SetOut(consoleOut);
				var color = ConsoleColor.Green;
				var status = "Passed";
				if (parts[1].Trim() != output.Trim())
				{
					color = ConsoleColor.Red;
					status = "Failed";
				}
				Console.ForegroundColor = color;
				Console.WriteLine("Test {0} {1} in {2}ms", i + 1, status, sw.ElapsedMilliseconds);
			}
			Console.ReadLine();
			Console.ReadKey();
#else
			new Template().Solve();
			Console.ReadLine();
#endif
		}
	}

	internal class Scanner
	{
		private string[] s = new string[0];
		private int i;
		private readonly char[] cs = { ' ' };

		public string NextString()
		{
			if (i < s.Length) return s[i++];
			var line = Console.ReadLine() ?? string.Empty;
			s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			i = 1;
			return s.First();
		}

		public double NextDouble()
		{
			return double.Parse(NextString());
		}

		public int NextInt()
		{
			return int.Parse(NextString());
		}

		public long NextLong()
		{
			return long.Parse(NextString());
		}
	}
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace Codeforces
{
	internal class Template
	{
		private List<int>[] adj = new List<int>[150100];
		private bool[] visited;

		private void Solve()
		{
			var n = cin.NextInt();
			var m = cin.NextInt();
			for (var i = 1; i <= n; i++)
			{
				adj[i] = new List<int>();
			}
			for (var i = 0; i < m; i++)
			{
				var a = cin.NextInt();
				var b = cin.NextInt();
				adj[a].Add(b);
				adj[b].Add(a);
			}
			visited = new bool[n + 10];
			for (var i = 1; i <= n; i++)
			{
				if (visited[i])
				{
					continue;
				}
				if (!Dfs(i))
				{
					Console.WriteLine("NO");
					return;
				}
			}
			Console.WriteLine("YES");
		}

		private bool Dfs(int v)
		{
			visited[v] = true;
			foreach (var child in adj[v])
			{
				if (!visited[child])
				{
					if (adj[v].Count != adj[child].Count)
					{
						return false;
					}
					Dfs(child);
				}
			}
			return true;
		}

		private static readonly Scanner cin = new Scanner();

		private static void Main()
		{
#if DEBUG
			var inputText = File.ReadAllText(@"..\..\input.txt");
			var testCases = inputText.Split(new[] { "input" }, StringSplitOptions.RemoveEmptyEntries);
			var consoleOut = Console.Out;
			for (var i = 0; i < testCases.Length; i++)
			{
				var parts = testCases[i].Split(new[] { "output" }, StringSplitOptions.RemoveEmptyEntries);
				Console.SetIn(new StringReader(parts[0].Trim()));
				var stringWriter = new StringWriter();
				Console.SetOut(stringWriter);
				var sw = Stopwatch.StartNew();
				new Template().Solve();
				sw.Stop();
				var output = stringWriter.ToString();

				Console.SetOut(consoleOut);
				var color = ConsoleColor.Green;
				var status = "Passed";
				if (parts[1].Trim() != output.Trim())
				{
					color = ConsoleColor.Red;
					status = "Failed";
				}
				Console.ForegroundColor = color;
				Console.WriteLine("Test {0} {1} in {2}ms", i + 1, status, sw.ElapsedMilliseconds);
			}
			Console.ReadLine();
			Console.ReadKey();
#else
			new Template().Solve();
			Console.ReadLine();
#endif
		}
	}

	internal class Scanner
	{
		private string[] s = new string[0];
		private int i;
		private readonly char[] cs = { ' ' };

		public string NextString()
		{
			if (i < s.Length) return s[i++];
			var line = Console.ReadLine() ?? string.Empty;
			s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			i = 1;
			return s.First();
		}

		public double NextDouble()
		{
			return double.Parse(NextString());
		}

		public int NextInt()
		{
			return int.Parse(NextString());
		}

		public long NextLong()
		{
			return long.Parse(NextString());
		}
	}
}


using System;
using System.Collections.Generic;

namespace _791B
{
    class Program
    {
        static long n, m;
        static List<long>[] graph;
        static bool[] visited;

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            n = long.Parse(input[0]); m = long.Parse(input[1]);
            graph = new List<long>[n];
            for (long i = 0; i < n; i++) graph[i] = new List<long>();
            for (long i = 0; i < m; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                long a = long.Parse(line[0]) - 1, b = long.Parse(line[1]) - 1;
                graph[a].Add(b);
                graph[b].Add(a);
            }
            bool result = true;
            for (long i = 0; i < n; i++)
            {
                if (visited[i]) continue;
                long edges = 0, vertices = 1;
                HashSet<Tuple<long, long>> visitedEdges = new HashSet<Tuple<long, long>>();
                DFS(i, -1, ref visitedEdges, ref edges, ref vertices);
                result = result && edges == (vertices * (vertices - 1)) / 2;
                if (!result) break;
            }
            Console.WriteLine(result ? "YES" : "NO");
        }

        static void DFS(long curr, long prev, ref HashSet<Tuple<long, long>> visitedEdges, ref long edges, ref long vertices)
        {
            visited[curr] = true;
            foreach (var x in graph[curr])
            {
                if (x == prev) continue;
                Tuple<long, long> t1 = new Tuple<long, long>(curr, x), t2 = new Tuple<long, long>(x, curr);
                if (!visitedEdges.Contains(t1))
                {
                    edges++;
                    visitedEdges.Add(t1);
                    visitedEdges.Add(t2);
                }
                if (!visited[x])
                {
                    vertices++;
                    DFS(x, curr, ref visitedEdges, ref edges, ref vertices);
                }
            }
        }
    }
}


using System;
using System.Collections.Generic;

namespace _791B
{
    class Program
    {
        static long n, m;
        static List<long>[] graph;
        static HashSet<long> visited;

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            n = long.Parse(input[0]); m = long.Parse(input[1]);
            graph = new List<long>[n];
            for (long i = 0; i < n; i++) graph[i] = new List<long>();
            for (long i = 0; i < m; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                long a = long.Parse(line[0]) - 1, b = long.Parse(line[1]) - 1;
                graph[a].Add(b);
                graph[b].Add(a);
            }
            visited = new HashSet<long>();
            bool result = true;
            for (long i = 0; i < n; i++)
            {
                if (visited.Contains(i)) continue;
                long edges = 0, vertices = 1;
                HashSet<Tuple<long, long>> visitedEdges = new HashSet<Tuple<long, long>>();
                DFS(i, -1, ref visitedEdges, ref edges, ref vertices);
                result = result && edges == (vertices * (vertices - 1)) / 2;
            }
            Console.WriteLine(result ? "YES" : "NO");
        }

        static void DFS(long curr, long prev, ref HashSet<Tuple<long, long>> visitedEdges, ref long edges, ref long vertices)
        {
            visited.Add(curr);
            foreach (var x in graph[curr])
            {
                if (x == prev) continue;
                Tuple<long, long> t1 = new Tuple<long, long>(curr, x), t2 = new Tuple<long, long>(x, curr);
                if (!visitedEdges.Contains(t1))
                {
                    edges++;
                    visitedEdges.Add(t1);
                    visitedEdges.Add(t2);
                }
                if (!visited.Contains(x))
                {
                    vertices++;
                    DFS(x, curr, ref visitedEdges, ref edges, ref vertices);
                }
            }
        }
    }
}


using System;
using System.Collections.Generic;

namespace _791B
{
    class Program
    {
        static long n, m;
        static List<long>[] graph;
        static bool[] visited;

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            n = long.Parse(input[0]); m = long.Parse(input[1]);
            graph = new List<long>[n];
            for (long i = 0; i < n; i++) graph[i] = new List<long>();
            for (long i = 0; i < m; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                long a = long.Parse(line[0]) - 1, b = long.Parse(line[1]) - 1;
                graph[a].Add(b);
                graph[b].Add(a);
            }
            visited = new bool[n];
            bool result = true;
            for (long i = 0; i < n; i++)
            {
                if (visited[i]) continue;
                long edges = 0, vertices = 0;
                DFS(i, -1, ref edges, ref vertices);
                result = result && (edges / 2) == (vertices * (vertices - 1)) / 2;
                if (!result) break;
            }
            Console.WriteLine(result ? "YES" : "NO");
        }

        static void DFS(long curr, long prev, ref long edges, ref long vertices)
        {
            visited[curr] = true;
            vertices++;
            foreach (var x in graph[curr])
            {
                edges++;
                if (x != prev && !visited[x])
                    DFS(x, curr, ref edges, ref vertices);
            }
        }
    }
}


using System;
using System.Collections.Generic;

namespace _791B
{
    class Program
    {
        static long n, m;
        static List<long>[] graph;
        static bool[] visited;

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            n = long.Parse(input[0]); m = long.Parse(input[1]);
            graph = new List<long>[n];
            for (long i = 0; i < n; i++) graph[i] = new List<long>();
            for (long i = 0; i < m; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                long a = long.Parse(line[0]) - 1, b = long.Parse(line[1]) - 1;
                graph[a].Add(b);
                graph[b].Add(a);
            }
            visited = new bool[n];
            bool result = true;
            for (long i = 0; i < n; i++)
            {
                if (visited[i]) continue;
                long edges = 0, vertices = 1;
                HashSet<Tuple<long, long>> visitedEdges = new HashSet<Tuple<long, long>>();
                DFS(i, -1, ref visitedEdges, ref edges, ref vertices);
                result = result && edges == (vertices * (vertices - 1)) / 2;
                if (!result) break;
            }
            Console.WriteLine(result ? "YES" : "NO");
        }

        static void DFS(long curr, long prev, ref HashSet<Tuple<long, long>> visitedEdges, ref long edges, ref long vertices)
        {
            visited[curr] = true;
            foreach (var x in graph[curr])
            {
                if (x == prev) continue;
                Tuple<long, long> t1 = new Tuple<long, long>(curr, x), t2 = new Tuple<long, long>(x, curr);
                if (!visitedEdges.Contains(t1))
                {
                    edges++;
                    visitedEdges.Add(t1);
                    visitedEdges.Add(t2);
                }
                if (!visited[x])
                {
                    vertices++;
                    DFS(x, curr, ref visitedEdges, ref edges, ref vertices);
                }
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace _791B
{
    class Program
    {
        static int n, m;
        static List<int>[] graph;
        static HashSet<int> visited;

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            n = int.Parse(input[0]); m = int.Parse(input[1]);
            graph = new List<int>[n];
            for (int i = 0; i < n; i++) graph[i] = new List<int>();
            for (int i = 0; i < m; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                int a = int.Parse(line[0]) - 1, b = int.Parse(line[1]) - 1;
                graph[a].Add(b);
                graph[b].Add(a);
            }
            visited = new HashSet<int>();
            bool result = true;
            for (int i = 0; i < n; i++)
            {
                if (visited.Contains(i)) continue;
                int edges = 0, vertices = 1;
                HashSet<Tuple<int, int>> visitedEdges = new HashSet<Tuple<int, int>>();
                DFS(i, -1, ref visitedEdges, ref edges, ref vertices);
                result = result && edges == (vertices * (vertices - 1)) / 2;
            }
            Console.WriteLine(result ? "YES" : "NO");
        }

        static void DFS(int curr, int prev, ref HashSet<Tuple<int, int>> visitedEdges, ref int edges, ref int vertices)
        {
            visited.Add(curr);
            foreach (var x in graph[curr])
            {
                if (x == prev) continue;
                Tuple<int, int> t1 = new Tuple<int, int>(curr, x), t2 = new Tuple<int, int>(x, curr);
                if (!visitedEdges.Contains(t1))
                {
                    edges++;
                    visitedEdges.Add(t1);
                    visitedEdges.Add(t2);
                }
                if (!visited.Contains(x))
                {
                    vertices++;
                    DFS(x, curr, ref visitedEdges, ref edges, ref vertices);
                }
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace _791B
{
    class Program
    {
        static int n, m;
        static List<int>[] graph;
        static HashSet<int> notVisited;

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            n = int.Parse(input[0]); m = int.Parse(input[1]);
            graph = new List<int>[n];
            for (int i = 0; i < n; i++) graph[i] = new List<int>();
            for (int i = 0; i < m; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                int a = int.Parse(line[0]) - 1, b = int.Parse(line[1]) - 1;
                graph[a].Add(b);
                graph[b].Add(a);
            }
            notVisited = new HashSet<int>();
            for (int i = 0; i < n; i++) notVisited.Add(i);
            bool result = true;
            while (notVisited.Count > 0)
            {
                int edges = 0, vertices = 1;
                HashSet<Tuple<int, int>> visitedEdges = new HashSet<Tuple<int, int>>();
                DFS(notVisited.First(), -1, ref visitedEdges, ref edges, ref vertices);
                result = result && edges == (vertices * (vertices - 1)) / 2;
            }
            Console.WriteLine(result ? "YES" : "NO");
        }

        static void DFS(int curr, int prev, ref HashSet<Tuple<int, int>> visitedEdges, ref int edges, ref int vertices)
        {
            notVisited.Remove(curr);
            foreach (var x in graph[curr])
            {
                if (x == prev) continue;
                Tuple<int, int> t1 = new Tuple<int, int>(curr, x), t2 = new Tuple<int, int>(x, curr);
                if (!visitedEdges.Contains(t1) && !visitedEdges.Contains(t2))
                {
                    edges++;
                    visitedEdges.Add(t1);
                    visitedEdges.Add(t2);
                }
                if (notVisited.Contains(x))
                {
                    vertices++;
                    DFS(x, curr, ref visitedEdges, ref edges, ref vertices);
                }
            }
        }
    }
}


using System;
using System.Globalization;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();

            var x = p.Solve();
            p.Out(x);
        }
        object Solve()
        {
            var n = ReadLong();
            var m = ReadLong();
            var dsu = new DSU((int) n);
            var pairs = new Tuple<long, long>[m];
            for (int i = 0; i < m; i++)
            {
                var p = ReadLongs();
                dsu.Union((int) p[0] - 1, (int)p[1] - 1);
                pairs[i] = Tuple.Create(p[0] - 1, p[1] - 1);
            }
            var counts = new long[n];
            for (int i = 0; i < m; i++)
            {
                var head = dsu.Find((int)pairs[i].Item1);
                counts[head]++;
            }
            var arr = dsu.Enumerate();

            foreach (var item in arr)
            {
                if (counts[item.Item1] > 0 && counts[item.Item1] != ((long)item.Item2) * (item.Item2 - 1) / 2)
                    return "NO";
            }
            return "YES";
        }

        long BS(long remain, long l, long r)
        {
            if (r - l == 1)
                return r;
            var half = (l + r) / 2;
            var sum = half * (half + 1) / 2;
            if (sum < remain)
                return BS(remain, half, r);
            return BS(remain, l, half);
        }

        class Pair
        {
            public long Val;
            public long Rem;
            public long Count1;
            public long Len;
        }

        Node FindDeepest(Node current, long target, Node bad)
        {
            Node result = null;
            for (int i = 0; i < current.Children.Count; i++)
            {
                if (current.Children[i] == bad)
                    continue;
                result = FindDeepest(current.Children[i], target, bad);
                if (result != null)
                {
                    break;
                }
            }
            if (current.parent != -1 && result == null && current.sum == target)
                return current;
            return result;
        }

        long CalcSum(Node current)
        {
            var sum = current.t;
            for (int i = 0; i < current.Children.Count; i++)
            {
                sum += CalcSum(current.Children[i]);
            }
            current.sum = sum;
            return sum;
        }

        class Node {
            public long parent;
            public long index;
            public long t;
            public long sum;
            public List<Node> Children;
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024 * 10)
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected string ReadToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return tokens.Dequeue();
        }

        protected long ReadLong() { return long.Parse(ReadToken()); }

        protected long[] ReadLongs()
        {
            var s = Read();
            if (s == "")
                return new long[0];
            //var i = s.IndexOf(' ');
            //return new[] { long.Parse(s.Substring(0, i)), long.Parse(s.Substring(i + 1)) };
            var tokens = s.Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> s, string d) { return string.Join(d, s.ToArray()); }

        public static string JoinStrings(this IEnumerable<int> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
        public static string JoinStrings(this IEnumerable<long> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
    }
    class DSU
    {
        private int[] arr;
        private Random r = new Random();
        public DSU(int n)
        {
            arr = new int[n];
            for (int i = 0; i < n; i++)
            {
                arr[i] = i;
            }
        }

        public int Find(int x)
        {
            if (arr[arr[x]] == arr[x])
                return arr[x];
            var y = Find(arr[x]);
            arr[x] = y;
            return y;
        }

        public void Union(int x, int y)
        {
            var p1 = Find(x);
            var p2 = Find(y);
            if (p1 == p2)
                return;
            if (r.NextDouble() < 0.5)
                arr[p1] = p2;
            else
                arr[p2] = p1;
        }

        public Tuple<int, int>[] Enumerate()
        {
            return arr.Select((x, i) => new { g = Find(x), i }).GroupBy(x => x.g, (k, e) => Tuple.Create(k, e.Count())).ToArray();
        }
    }

}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var sr = new InputReader(Console.In);
            //var sr = new InputReader(new StreamReader("input.txt"));
            var task = new Task();
            using (var sw = Console.Out)
            {
                //using (var sw = new StreamWriter("output.txt")) {
                task.Solve(sr, sw);
                //Console.ReadKey();
            }
        }
    }

    internal class Task
    {
        public void Solve(InputReader sr, TextWriter sw)
        {
            var input = sr.ReadArray(Int32.Parse);
            var n = input[0];
            var m = input[1];
            var friends = new HashSet<int>[n + 1];
            var table = new bool[n + 1, n + 1];
            var array = new Tuple<int, int>[m];
            for (var i = 0; i < m; i++) {
                input = sr.ReadArray(Int32.Parse);
                var a = input[0];
                var b = input[1];
                if (friends[a] == null) {
                    friends[a] = new HashSet<int>();
                }
                friends[a].Add(b);
                if (friends[b] == null) {
                    friends[b] = new HashSet<int>();
                }
                friends[b].Add(a);
                array[i] = new Tuple<int, int>(a, b);
                table[a, b] = true;
                table[b, a] = true;
            }
            for (var i = 0; i < n; i++) {
                if (friends[i] != null) {
                    foreach (var hisFriends in friends[i]) {
                        foreach (var fr in friends[hisFriends])
                        {
                            if (fr == i)
                                continue;
                            if (!table[fr, i])
                            {
                                sw.WriteLine("NO");
                                return;
                            }
                        }
                    }
                }
            }

            sw.WriteLine("YES");
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(NextString());
    }

    public long NextInt64()
    {
        return Int64.Parse(NextString());
    }

    public string[] NextSplitStrings()
    {
        return NextString()
                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
                str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                        .Select(s => func(s, CultureInfo.InvariantCulture))
                        .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();
            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var sr = new InputReader(Console.In);
            //var sr = new InputReader(new StreamReader("input.txt"));
            var task = new Task();
            using (var sw = Console.Out)
            {
                //using (var sw = new StreamWriter("output.txt")) {
                task.Solve(sr, sw);
                //Console.ReadKey();
            }
        }
    }

    internal class Task
    {
        public void Solve(InputReader sr, TextWriter sw)
        {
            var input = sr.ReadArray(Int32.Parse);
            var n = input[0];
            var m = input[1];
            var friends = new HashSet<int>[n + 1];
            var array = new Tuple<int, int>[m];
            for (var i = 0; i < m; i++) {
                input = sr.ReadArray(Int32.Parse);
                var a = input[0];
                var b = input[1];
                if (friends[a] == null) {
                    friends[a] = new HashSet<int>();
                }
                friends[a].Add(b);
                if (friends[b] == null) {
                    friends[b] = new HashSet<int>();
                }
                friends[b].Add(a);
                array[i] = new Tuple<int, int>(a, b);
            }
            for (var i = 0; i < n; i++) {
                if (friends[i] != null) {
                    foreach (var hisFriends in friends[i]) {
                        foreach (var fr in friends[hisFriends])
                        {
                            if (fr == i)
                                continue;
                            if (!friends[i].Contains(fr))
                            {
                                sw.WriteLine("NO");
                                return;
                            }
                        }
                    }
                }
            }

            sw.WriteLine("YES");
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(NextString());
    }

    public long NextInt64()
    {
        return Int64.Parse(NextString());
    }

    public string[] NextSplitStrings()
    {
        return NextString()
                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
                str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                        .Select(s => func(s, CultureInfo.InvariantCulture))
                        .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();
            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var sr = new InputReader(Console.In);
            //var sr = new InputReader(new StreamReader("input.txt"));
            var task = new Task();
            using (var sw = Console.Out)
            {
                //using (var sw = new StreamWriter("output.txt")) {
                task.Solve(sr, sw);
                //Console.ReadKey();
            }
        }
    }

    internal class Task
    {
        public void Solve(InputReader sr, TextWriter sw)
        {
            var input = sr.ReadArray(Int32.Parse);
            var n = input[0];
            var m = input[1];
            var graph = new Graph(n);
            for (var i = 0; i < m; i++)
            {
                input = sr.ReadArray(Int32.Parse);
                graph.Insert(input[0] - 1, input[1] - 1);
            }
            if (graph.Components())
            {
                sw.WriteLine("YES");
            }
            else
            {
                sw.WriteLine("NO");
            }
        }
    }

    class Graph
    {
        private readonly List<int>[] edges;

        public Graph(int n)
        {
            edges = new List<int>[n];
        }

        public void Insert(int x, int y)
        {
            if (edges[x] == null)
            {
                edges[x] = new List<int>();
            }
            edges[x].Add(y);
            if (edges[y] == null)
            {
                edges[y] = new List<int>();
            }
            edges[y].Add(x);
        }

        public bool Components()
        {
            var visited = new bool[edges.Length];
            for (var i = 0; i < edges.Length; i++)
            {
                if (!visited[i])
                {
                    var comp = new List<int>();
                    DfsVisit(i, visited, comp);
                    var need = comp.Count - 1;
                    if (comp.Count != 1) {
                        for (var j = 0; j < comp.Count; j++) {
                            if (edges[comp[j]].Count != need) {
                                return false;
                            }
                        }
                    }
                }
            }

            return true;
        }

        private void DfsVisit(int v, bool[] visited, List<int> comp)
        {
            visited[v] = true;
            comp.Add(v);
            if (edges[v] != null)
            {
                for (var i = 0; i < edges[v].Count; i++)
                {
                    if (!visited[edges[v][i]])
                    {
                        DfsVisit(edges[v][i], visited, comp);
                    }
                }
            }
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(NextString());
    }

    public long NextInt64()
    {
        return Int64.Parse(NextString());
    }

    public string[] NextSplitStrings()
    {
        return NextString()
                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
                str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                        .Select(s => func(s, CultureInfo.InvariantCulture))
                        .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();
            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var sr = new InputReader(Console.In);
            //var sr = new InputReader(new StreamReader("input.txt"));
            var task = new Task();
            using (var sw = Console.Out)
            {
                //using (var sw = new StreamWriter("output.txt")) {
                task.Solve(sr, sw);
                //Console.ReadKey();
            }
        }
    }

    internal class Task
    {
        public void Solve(InputReader sr, TextWriter sw)
        {
            var input = sr.ReadArray(Int32.Parse);
            var n = input[0];
            var m = input[1];
            var friends = new Dictionary<int, HashSet<int>>();
            var array = new Tuple<int, int>[m];
            for (var i = 0; i < m; i++) {
                input = sr.ReadArray(Int32.Parse);
                var a = input[0];
                var b = input[1];
                if (!friends.ContainsKey(a)) {
                    friends.Add(a, new HashSet<int>());
                }
                friends[a].Add(b);
                if (!friends.ContainsKey(b)) {
                    friends.Add(b, new HashSet<int>());
                }
                friends[b].Add(a);
                array[i] = new Tuple<int, int>(a, b);
            }
            foreach (var item in friends) {
                foreach (var hisFriends in item.Value) {
                    foreach (var fr in friends[hisFriends]) {
                        if (fr == item.Key)
                            continue;
                            if (!item.Value.Contains(fr)) {
                                sw.WriteLine("NO");
                                return;
                            }
                    }
                }
            }

            sw.WriteLine("YES");
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(NextString());
    }

    public long NextInt64()
    {
        return Int64.Parse(NextString());
    }

    public string[] NextSplitStrings()
    {
        return NextString()
                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
                str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                        .Select(s => func(s, CultureInfo.InvariantCulture))
                        .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();
            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication38
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] linea = Console.ReadLine().Split();
            int N = int.Parse(linea[0]);
            int M = int.Parse(linea[1]);
            Node[] Vertices = new Node[N + 5];
            for (int i = 0; i < Vertices.Length; i++)
            {
                Vertices[i] = new Node(i);
            }
            for (int i = 0; i < M; i++)
            {
                string[] linea1 = Console.ReadLine().Split();
                int A = int.Parse(linea1[0]);
                int B = int.Parse(linea1[1]);
                Node A1 = setof(Vertices[A-1]);
                Node A2 = setof(Vertices[B-1]);
                JoinSet(A1, A2);
            }
            bool verify = true;
            long e = 2;
            for (int i = 0; i < Vertices.Length; i++)
            {
                if (Vertices[i].Father == null)
                {
                    if (Vertices[i].Aristas != (Vertices[i].CantVer * (Vertices[i].CantVer - 1)) / e)
                    {
                        verify = false;
                        break;
                    }
                }
            }

            if (verify)
            {
                Console.WriteLine("YES");
            }
            else { Console.WriteLine("NO"); }

        }

        public static Node setof(Node A)
        {
            if (A.Father == null)
            {
                return A;
            }

            Node Aux = setof(A.Father);
            A.Father = Aux;
            return Aux;
        }

        public static void JoinSet(Node A, Node B)
        {
            if (A.Value == B.Value)
            {
                A.Aristas++;
                return;
            }
            B.Father = A;
            A.CantVer += B.CantVer;
            A.Aristas += B.Aristas + 1;
            return;
        }
    }

    public class Node
    {
       public Node Father;
       public long CantVer;
       public long Value;
       public long Aristas;

        public Node(int Value)
        {
            Father = null;
            CantVer = 1;
            Aristas = 0;
            this.Value = Value;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication32
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] linea = Console.ReadLine().Split();
            int N = int.Parse(linea[0]);
            int M = int.Parse(linea[1]);
            Node[] Vertices = new Node[N];
            for (int i = 0; i < N; i++)
            {
                Vertices[i] = new Node(i + 1);
            }
            for (int i = 0; i < M; i++)
            {
                string[] Aux = Console.ReadLine().Split();
                int A = int.Parse(Aux[0]);
                int B = int.Parse(Aux[1]);
                FindFather(Vertices[A - 1], Vertices[B - 1]);
            }
            bool Verify = true;
            for (int i = 0; i < Vertices.Length; i++)
            {
                if (Vertices[i].Father == null)
                {
                    if (Vertices[i].Aristas != ((Vertices[i].CantVer) * (Vertices[i].CantVer - 1)) / 2) { Verify = false; break; }
                }
            }
            if (Verify)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }

        public static void FindFather(Node A, Node B)
        {
            if (A.Father == null && B.Father == null)
            {
                A.JoinSet(A, B);
                return;
            }

            if (A.Father != null && B.Father != null)
            {
                FindFather(A.Father, B.Father);
                return;
            }
            else
            {
                if (A.Father != null)
                {
                    FindFather(A.Father, B);
                    return;
                }
                else
                {
                    FindFather(A, B.Father);
                    return;
                }
            }
        }
    }

    public class Node
    {
        public Node Father;
        public int Alt;
        public int CantVer;
        public int Value;
        public int Aristas;

        public Node(int Value)
        {
            Father = null;
            Alt = 0;
            CantVer = 1;
            Aristas = 0;
            this.Value = Value;
        }

        public void JoinSet(Node A, Node B)
        {
            if (A.Value == B.Value)
            {
                A.Aristas++;
            }
            else
            {
                if (A.Alt == B.Alt)
                {
                    B.Father = A;
                    A.CantVer += B.CantVer;
                    A.Alt++;
                    A.Aristas += B.Aristas + 1;
                }
                else
                {
                    if (A.Alt > B.Alt)
                    {
                        B.Father = A;
                        A.CantVer += B.CantVer;
                        A.Aristas += B.Aristas + 1;
                    }
                    else
                    {
                        A.Father = B;
                        B.CantVer += A.CantVer;
                        B.Aristas += A.Aristas + 1;
                    }
                }
            }

        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication32
{
    class Program
    {
        public static int[] Array1;
        static void Main(string[] args)
        {
            string[] linea = Console.ReadLine().Split();
            int N = int.Parse(linea[0]);
            int M = int.Parse(linea[1]);
            Array1 = new int[N];
            Node[] Vertices = new Node[N];
            for (int i = 0; i < N; i++)
            {
                Vertices[i] = new Node(i + 1);
            }
            for (int i = 0; i < M; i++)
            {
                string[] Aux = Console.ReadLine().Split();
                int A = int.Parse(Aux[0]);
                int B = int.Parse(Aux[1]);
                FindFather(Vertices[A - 1], Vertices[B - 1]);
            }
            bool Verify = true;
            for (int i = 0; i < Array1.Length; i++)
            {
                if (Array1[i] != -1)
                {
                    if (Vertices[i].Aristas != ((Vertices[i].CantVer) * (Vertices[i].CantVer - 1)) / 2) { Verify = false; break; }
                }
            }
            if (Verify)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }

        public static void FindFather(Node A, Node B)
        {
            if (A.Father == null && B.Father == null)
            {
                A.JoinSet(A, B, Array1);
                return;
            }

            if (A.Father != null && B.Father != null)
            {
                FindFather(A.Father, B.Father);
                return;
            }
            else
            {
                if (A.Father != null)
                {
                    FindFather(A.Father, B);
                    return;
                }
                else
                {
                    FindFather(A, B.Father);
                    return;
                }
            }
        }
    }

    public class Node
    {
        public Node Father;
        public int Alt;
        public int CantVer;
        public int Value;
        public int Aristas;

        public Node(int Value)
        {
            Father = null;
            Alt = 0;
            CantVer = 1;
            Aristas = 0;
            this.Value = Value;
        }

        public void JoinSet(Node A, Node B, int[] Array1)
        {
            if (A.Value == B.Value)
            {
                A.Aristas++;
            }
            else
            {
                if (A.Alt == B.Alt)
                {
                    B.Father = A;
                    A.CantVer += B.CantVer;
                    A.Alt++;
                    A.Aristas += B.Aristas + 1;
                    Array1[A.Value - 1] = -1;
                    Array1[B.Value - 1] = -1;
                    Array1[A.Value - 1] = 0;
                }
                else
                {
                    if (A.Alt > B.Alt)
                    {
                        B.Father = A;
                        A.CantVer += B.CantVer;
                        A.Aristas += B.Aristas + 1;
                        Array1[A.Value - 1] = -1;
                        Array1[B.Value - 1] = -1;
                        Array1[A.Value - 1] = 0;
                    }
                    else
                    {
                        A.Father = B;
                        B.CantVer += A.CantVer;
                        B.Aristas += A.Aristas + 1;
                        Array1[A.Value - 1] = -1;
                        Array1[B.Value - 1] = -1;
                        Array1[B.Value - 1] = 0;
                    }
                }
            }

        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication32
{
    class Program
    {
        public static List<int> Array1;
        static void Main(string[] args)
        {
            string[] linea = Console.ReadLine().Split();
            int N = int.Parse(linea[0]);
            int M = int.Parse(linea[1]);
            Array1 = new List<int>();
            Node[] Vertices = new Node[N];
            for (int i = 0; i < N; i++)
            {
                Vertices[i] = new Node(i + 1);
            }
            for (int i = 0; i < M; i++)
            {
                string[] Aux = Console.ReadLine().Split();
                int A = int.Parse(Aux[0]);
                int B = int.Parse(Aux[1]);
                FindFather(Vertices[A - 1], Vertices[B - 1]);
            }
            bool Verify = true;
            for (int i = 0; i < Array1.Count; i++)
            {
                if (Vertices[Array1[i] - 1].Aristas != ((Vertices[Array1[i] - 1].CantVer) * (Vertices[Array1[i] - 1].CantVer - 1)) / 2) { Verify = false; break; }

            }
            if (Verify)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }

        public static void FindFather(Node A, Node B)
        {
            if (A.Father == null && B.Father == null)
            {
                A.JoinSet(A, B, Array1);
                return;
            }

            if (A.Father != null && B.Father != null)
            {
                FindFather(A.Father, B.Father);
                return;
            }
            else
            {
                if (A.Father != null)
                {
                    FindFather(A.Father, B);
                    return;
                }
                else
                {
                    FindFather(A, B.Father);
                    return;
                }
            }
        }
    }

    public class Node
    {
        public Node Father;
        public int Alt;
        public int CantVer;
        public int Value;
        public int Aristas;

        public Node(int Value)
        {
            Father = null;
            Alt = 0;
            CantVer = 1;
            Aristas = 0;
            this.Value = Value;
        }

        public void JoinSet(Node A, Node B, List<int> Array1)
        {
            if (A.Value == B.Value)
            {
                A.Aristas++;
            }
            else
            {
                if (A.Alt == B.Alt)
                {
                    B.Father = A;
                    A.CantVer += B.CantVer;
                    A.Alt++;
                    A.Aristas += B.Aristas + 1;
                    Array1.Remove(A.Value);
                    Array1.Remove(B.Value);
                    Array1.Add(A.Value);
                }
                else
                {
                    if (A.Alt > B.Alt)
                    {
                        B.Father = A;
                        A.CantVer += B.CantVer;
                        A.Aristas += B.Aristas + 1;
                        Array1.Remove(A.Value);
                        Array1.Remove(B.Value);
                        Array1.Add(A.Value);
                    }
                    else
                    {
                        A.Father = B;
                        B.CantVer += A.CantVer;
                        B.Aristas += A.Aristas + 1;
                        Array1.Remove(A.Value);
                        Array1.Remove(B.Value);
                        Array1.Add(B.Value);
                    }
                }
            }

        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication38
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] linea = Console.ReadLine().Split();
            int N = int.Parse(linea[0]);
            int M = int.Parse(linea[1]);
            Node[] Vertices = new Node[N];
            for (int i = 0; i < Vertices.Length; i++)
            {
                Vertices[i] = new Node(i);
            }
            for (int i = 0; i < M; i++)
            {
                string[] linea1 = Console.ReadLine().Split();
                int A = int.Parse(linea1[0]);
                int B = int.Parse(linea1[1]);
                Node A1 = setof(Vertices[A-1]);
                Node A2 = setof(Vertices[B-1]);
                JoinSet(A1, A2);
            }
            bool verify = true;
            for (int i = 0; i < Vertices.Length; i++)
            {
                if (Vertices[i].Father == null)
                {
                    if (Vertices[i].Aristas != (Vertices[i].CantVer * (Vertices[i].CantVer - 1)) / 2)
                    {
                        verify = false;
                        break;
                    }
                }
            }

            if (verify)
            {
                Console.WriteLine("YES");
            }
            else { Console.WriteLine("NO"); }

        }

        public static Node setof(Node A)
        {
            if (A.Father == null)
            {
                return A;
            }

            Node Aux = setof(A.Father);
            A.Father = Aux;
            return Aux;
        }

        public static void JoinSet(Node A, Node B)
        {
            if (A.Value == B.Value)
            {
                A.Aristas++;
                return;
            }
            B.Father = A;
            A.CantVer += B.CantVer;
            A.Aristas += B.Aristas + 1;
            return;
        }
    }

    public class Node
    {
       public Node Father;
       public int CantVer;
       public int Value;
       public int Aristas;

        public Node(int Value)
        {
            Father = null;
            CantVer = 1;
            Aristas = 0;
            this.Value = Value;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication32
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] linea = Console.ReadLine().Split();
            int N = int.Parse(linea[0]);
            int M = int.Parse(linea[1]);
            if (N < M)
            {
                if (M == (N * (N - 1)) / 2) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); }
            }
            else
            {
                Node[] Vertices = new Node[N];
                for (int i = 0; i < N; i++)
                {
                    Vertices[i] = new Node(i + 1);
                }
                for (int i = 0; i < M; i++)
                {
                    string[] Aux = Console.ReadLine().Split();
                    int A = int.Parse(Aux[0]);
                    int B = int.Parse(Aux[1]);
                    FindFather(Vertices[A - 1], Vertices[B - 1]);
                }
                bool Verify = true;
                for (int i = 0; i < Vertices.Length; i++)
                {
                    if (Vertices[i].Father == null)
                    {
                        if (Vertices[i].Aristas != ((Vertices[i].CantVer) * (Vertices[i].CantVer - 1)) / 2) { Verify = false; break; }
                    }
                }
                if (Verify)
                {
                    Console.WriteLine("YES");
                }
                else
                {
                    Console.WriteLine("NO");
                }
            }
        }

        public static void FindFather(Node A, Node B)
        {
            if (A.Father == null && B.Father == null)
            {
                A.JoinSet(A, B);
                return;
            }

            if (A.Father != null && B.Father != null)
            {
                FindFather(A.Father, B.Father);
                return;
            }
            else
            {
                if (A.Father != null)
                {
                    FindFather(A.Father, B);
                    return;
                }
                else
                {
                    FindFather(A, B.Father);
                    return;
                }
            }
        }
    }

    public class Node
    {
        public Node Father;
        public int Alt;
        public int CantVer;
        public int Value;
        public int Aristas;

        public Node(int Value)
        {
            Father = null;
            Alt = 0;
            CantVer = 1;
            Aristas = 0;
            this.Value = Value;
        }

        public void JoinSet(Node A, Node B)
        {
            if (A.Value == B.Value)
            {
                A.Aristas++;
            }
            else
            {
                if (A.Alt == B.Alt)
                {
                    B.Father = A;
                    A.CantVer += B.CantVer;
                    A.Alt++;
                    A.Aristas += B.Aristas + 1;
                }
                else
                {
                    if (A.Alt > B.Alt)
                    {
                        B.Father = A;
                        A.CantVer += B.CantVer;
                        A.Aristas += B.Aristas + 1;
                    }
                    else
                    {
                        A.Father = B;
                        B.CantVer += A.CantVer;
                        B.Aristas += A.Aristas + 1;
                    }
                }
            }

        }

    }
}


using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] a = Console.ReadLine().Split(' ');
            int m = Convert.ToInt32(a[0]);
            int n = Convert.ToInt32(a[1]);

            Dictionary<int, List<int>> network = new Dictionary<int, List<int>>();
            Dictionary<int, HashSet<int>> network2 = new Dictionary<int, HashSet<int>>();

            HashSet<int> done = new HashSet<int>();

            for (int i = 0; i < n; i++)
            {
                string[] data = Console.ReadLine().Split(' ');
                int a1 = Convert.ToInt32(data[0]);
                int b = Convert.ToInt32(data[1]);

                if (!network.ContainsKey(a1))
                {
                    network[a1] = new List<int>();
                    network2[a1] = new HashSet<int>();
                }

                if (!network.ContainsKey(b))
                {
                    network[b] = new List<int>();
                    network2[b] = new HashSet<int>();
                }

                network[a1].Add(b);
                network[b].Add(a1);

                network2[a1].Add(b);
                network2[b].Add(a1);
            }

            bool answered = false;
            foreach (var key in network.Keys)
            {
                for (int i = 0; i < network[key].Count; i++)
                {
                    var list1 = network[key];
                    var key2 = network[key][i];
                    var list2 = network[key2];

                    if(done.Contains(key2))
                    {
                        continue;
                    }

                    if (list1.Count != list2.Count)
                    {
                        answered = true;
                        Console.WriteLine("NO");
                        return;
                    }
                    else
                    {
                        foreach (var friend in network2[key])
                        {
                            if (!network2[key2].Contains(friend) && friend != key && friend != key2)
                            {
                                answered = true;
                                Console.WriteLine("NO");
                                return;
                            }
                            else
                            {
                                done.Add(key2);
                            }
                        }
                    }
                }
            }

            if (!answered)
            {
                Console.WriteLine("YES");
            }
        }
    }
}


using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] a = Console.ReadLine().Split(' ');
            int m = Convert.ToInt32(a[0]);
            int n = Convert.ToInt32(a[1]);

            Dictionary<int, List<int>> network = new Dictionary<int, List<int>>();
            for(int i = 0; i < n; i++)
            {
                string[] data = Console.ReadLine().Split(' ');
                int a1 = Convert.ToInt32(data[0]);
                int b = Convert.ToInt32(data[1]);

                if (!network.ContainsKey(a1))
                {
                    network[a1] = new List<int>();
                }

                if (!network.ContainsKey(b))
                {
                    network[b] = new List<int>();
                }

                network[a1].Add(b);
                network[b].Add(a1);
            }

            bool answered = false;
            foreach(var key in network.Keys)
            {
                for(int i = 0; i < network[key].Count; i++)
                {
                    var list1 = network[key];
                    var key2 = network[key][i];
                    var list2 = network[key2];

                    if (list1.Count != list2.Count)
                    {
                        answered = true;
                        Console.WriteLine("NO");
                        return;
                    }
                    else
                    {
                        foreach(var friend in list1)
                        {
                            if (!list2.Contains(friend) && friend != key && friend != key2)
                            {
                                answered = true;
                                Console.WriteLine("NO");
                                return;
                            }
                        }
                    }
                }
            }

            if (!answered)
            {
                Console.WriteLine("YES");
            }
        }
    }
}