import java.util.*;
import java.io.*;

public  class TestClass{
    static ArrayList<Integer>[] al2;
         static class Pair implements Comparator<Pair>{
  int a;
  int b;
  Pair(){

  }

  Pair(int a,int b){
    this.a=a;
    this.b=b;
  }
  public int compare(Pair p1,Pair p2){

    return p1.a-p2.a;
 }
}

   static InputReader sc = new InputReader();
   static int gcd(int a,int b){
    if(a==0){
      return b;
    }
    return gcd(b%a,a);
   }
   static int d;
   static int[] color;
   static boolean[] v;
    /*static void dfs(int src,int x,int y){
      v[src]=true;
     int  i=1;
     color[src]=x;
      for(int a :al[src]){
        if(v[a]) continue;
        if(i==x|| i==y){
          i++;
          if(i==x|| i==y){
          i++;
        }
        }
        color[a]=i;
        i++;

      }
      for(int a:al[src]){
        if(!v[a]){
          dfs(a,color[a],x);
        }
      }

    }

*/
public static boolean isvowel(char ch){
    if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'){
        return true;
    }else{
        return false;
    }
}

 static ArrayList[] al;
static int n;
static int[] level;
static boolean[] visited;

    public static void main(String[] args) throws IOException{
      n=i(); int m=i();
            al=new ArrayList[n+1];
            level=new int[n+1];
            visited=new boolean[n+1];
         for (int i=0;i<=n ;i++ ) {
             al[i]=new ArrayList();
           }
         for(int i=0;i<m;i++){
          int a=i();
          int b=i();
          al[a].add(b);
          al[b].add(a);
         }
         boolean[] b=new boolean[n+1];
          for(int i=1;i<=n;i++){
              if(!visited[i]){
                  Bfs(i);

              }
          }
          for(int i=0;i<=n;i++){
              if(level[i]>1){
                System.out.println("NO");
 return;
              }
          }

 System.out.println("YES");
 return;

      }

           public static void Bfs(int node){

          Queue q=new LinkedList();
          visited[node]=true;
          q.add(node);
          while(!q.isEmpty()){

              int x=(int)q.remove();

              visited[x]=true;
              Iterator i=al[x].listIterator();

              while(i.hasNext()){
                int m=(int)i.next();
                if(visited[m]==false){
                q.add(m);
                level[m]=1+level[x];
                visited[m]=true;
              }
              }

        }
      }

    /////////////////////////////////////////////////////////// shortcuts //////////////////////////////
  /*    public static long modPow(long base, long exp, long mod) {
        base = base % mod;
        long result = 1;
        while (exp > 0) {
            if (exp % 2 == 1) {
                result = (result * base) % mod;
                exp--;
            } else {
                base = (base * base) % mod;
                exp = exp >> 1;
            }

        }
        return result;
    }

    public static void cal() {
        fac = new long[1000005];
        inv = new long[1000005];
        fac[0] = 1;
        inv[0] = 1;
        for (int i = 1; i <= 1000000; i++) {
            fac[i] = (fac[i - 1] * i) % mod;
            inv[i] = (inv[i - 1] * modPow(i, mod - 2, mod)) % mod;
        }
    }
 */
   /* public static long ncr(int n, int r) {
        return (((fac[n] * inv[r]) % mod) * inv[n - r]) % mod;
    }
 */

      static int i() {

          return sc.nextInt();
        }
        static long l() throws IOException{
          return sc.nextLong();

        }
        static double d() throws IOException{
          return sc.nextDouble();
        }
        static String s() throws IOException{
          return sc.next();

        }
        static String sL() throws IOException{
          return sc.nextLine();
        }
       static void loop(int[] a) throws IOException{
          for(int j=0;j<a.length;j++){
              a[j]=i();
          }
        }
        static void eloop(int[] a) throws IOException{
          for(int i=1;i<=a.length;i++){
              a[i]=i();
          }
        }
        static void ploop(int[] a)throws IOException{
             for(int j=0;j<a.length;j++){
                System.out.println(a[j]);
             }

        }
        static void eploop(int[] a)throws IOException{
             for(int j=1;j<=a.length;j++){
                System.out.println(a[j]);
             }

        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////

  static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                throw new RuntimeException();
            }
            return str;
        }
    }

 }


import java.util.*;
import java.io.*;

public  class TestClass{
    static ArrayList<Integer>[] al;
         static class Pair implements Comparator<Pair>{
  int a;
  int b;
  Pair(){

  }

  Pair(int a,int b){
    this.a=a;
    this.b=b;
  }
  public int compare(Pair p1,Pair p2){

    return p1.a-p2.a;
 }
}

   static InputReader sc = new InputReader();
   static int gcd(int a,int b){
    if(a==0){
      return b;
    }
    return gcd(b%a,a);
   }
   static int d;
   static int[] color;
   static boolean[] v;
    static void dfs(int src,int x,int y){
      v[src]=true;
     int  i=1;
     color[src]=x;
      for(int a :al[src]){
        if(v[a]) continue;
        if(i==x|| i==y){
          i++;
          if(i==x|| i==y){
          i++;
        }
        }
        color[a]=i;
        i++;

      }
      for(int a:al[src]){
        if(!v[a]){
          dfs(a,color[a],x);
        }
      }

    }

public static boolean isvowel(char ch){
    if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'){
        return true;
    }else{
        return false;
    }
}

    public static void main(String[] args) throws IOException{
      int n=i(); int m=i();

         ArrayList[] al=new ArrayList[n+1];
         for (int i=0;i<=n ;i++ ) {
             al[i]=new ArrayList();
           }
         for(int i=0;i<m;i++){
          int a=i();
          int b=i();
          al[a].add(b);
          al[b].add(a);
         }
         for(int i=1;i<=n;i++){
          if(al[i].size()>0){
            Iterator it=al[i].iterator();
            while(it.hasNext()){
              Iterator m1=al[(int)it.next()].iterator();
              while(m1.hasNext()){
                int k=(int)m1.next();
                if(k!=i &&!al[i].contains(k)){
                  System.out.println("NO");
                  return;
                }

              }

            }

          }

         }
         System.out.println("YES");

      }

    /////////////////////////////////////////////////////////// shortcuts //////////////////////////////
  /*    public static long modPow(long base, long exp, long mod) {
        base = base % mod;
        long result = 1;
        while (exp > 0) {
            if (exp % 2 == 1) {
                result = (result * base) % mod;
                exp--;
            } else {
                base = (base * base) % mod;
                exp = exp >> 1;
            }

        }
        return result;
    }

    public static void cal() {
        fac = new long[1000005];
        inv = new long[1000005];
        fac[0] = 1;
        inv[0] = 1;
        for (int i = 1; i <= 1000000; i++) {
            fac[i] = (fac[i - 1] * i) % mod;
            inv[i] = (inv[i - 1] * modPow(i, mod - 2, mod)) % mod;
        }
    }
 */
   /* public static long ncr(int n, int r) {
        return (((fac[n] * inv[r]) % mod) * inv[n - r]) % mod;
    }
 */

      static int i() {

          return sc.nextInt();
        }
        static long l() throws IOException{
          return sc.nextLong();

        }
        static double d() throws IOException{
          return sc.nextDouble();
        }
        static String s() throws IOException{
          return sc.next();

        }
        static String sL() throws IOException{
          return sc.nextLine();
        }
       static void loop(int[] a) throws IOException{
          for(int j=0;j<a.length;j++){
              a[j]=i();
          }
        }
        static void eloop(int[] a) throws IOException{
          for(int i=1;i<=a.length;i++){
              a[i]=i();
          }
        }
        static void ploop(int[] a)throws IOException{
             for(int j=0;j<a.length;j++){
                System.out.println(a[j]);
             }

        }
        static void eploop(int[] a)throws IOException{
             for(int j=1;j<=a.length;j++){
                System.out.println(a[j]);
             }

        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////

  static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                throw new RuntimeException();
            }
            return str;
        }
    }

 }


import java.util.*;
import java.io.*;

public  class TestClass{
    static ArrayList<Integer>[] al2;
         static class Pair implements Comparator<Pair>{
  int a;
  int b;
  Pair(){

  }

  Pair(int a,int b){
    this.a=a;
    this.b=b;
  }
  public int compare(Pair p1,Pair p2){

    return p1.a-p2.a;
 }
}

   static InputReader sc = new InputReader();
   static int gcd(int a,int b){
    if(a==0){
      return b;
    }
    return gcd(b%a,a);
   }
   static int d;
   static int[] color;
   static boolean[] v;
    /*static void dfs(int src,int x,int y){
      v[src]=true;
     int  i=1;
     color[src]=x;
      for(int a :al[src]){
        if(v[a]) continue;
        if(i==x|| i==y){
          i++;
          if(i==x|| i==y){
          i++;
        }
        }
        color[a]=i;
        i++;

      }
      for(int a:al[src]){
        if(!v[a]){
          dfs(a,color[a],x);
        }
      }

    }

*/
public static boolean isvowel(char ch){
    if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'){
        return true;
    }else{
        return false;
    }
}

 static ArrayList[] al;
static int n;
static int[] level;
static boolean[] visited;

    public static void main(String[] args) throws IOException{
      n=i(); int m=i();
            al=new ArrayList[n+1];
            level=new int[n+1];
            visited=new boolean[n+1];
         for (int i=0;i<=n ;i++ ) {
             al[i]=new ArrayList();
           }
         for(int i=0;i<m;i++){
          int a=i();
          int b=i();
          al[a].add(b);
          al[b].add(a);
         }
         boolean[] b=new boolean[n+1];
          for(int j=1;j<=n;j++){

                  Bfs(j);
                 for(int i=0;i<=n;i++){
              if(level[i]>1){
                System.out.println("NO");
                return;
              }
          }
          level=new int[n+1];
          visited=new boolean[n+1];

          }

 System.out.println("YES");
 return;

      }

           public static void Bfs(int node){

          Queue q=new LinkedList();
          visited[node]=true;
          q.add(node);
          while(!q.isEmpty()){

              int x=(int)q.remove();

              visited[x]=true;
              Iterator i=al[x].listIterator();

              while(i.hasNext()){
                int m=(int)i.next();
                if(visited[m]==false){
                q.add(m);
                level[m]=1+level[x];
                visited[m]=true;
              }
              }

        }
      }

    /////////////////////////////////////////////////////////// shortcuts //////////////////////////////
  /*    public static long modPow(long base, long exp, long mod) {
        base = base % mod;
        long result = 1;
        while (exp > 0) {
            if (exp % 2 == 1) {
                result = (result * base) % mod;
                exp--;
            } else {
                base = (base * base) % mod;
                exp = exp >> 1;
            }

        }
        return result;
    }

    public static void cal() {
        fac = new long[1000005];
        inv = new long[1000005];
        fac[0] = 1;
        inv[0] = 1;
        for (int i = 1; i <= 1000000; i++) {
            fac[i] = (fac[i - 1] * i) % mod;
            inv[i] = (inv[i - 1] * modPow(i, mod - 2, mod)) % mod;
        }
    }
 */
   /* public static long ncr(int n, int r) {
        return (((fac[n] * inv[r]) % mod) * inv[n - r]) % mod;
    }
 */

      static int i() {

          return sc.nextInt();
        }
        static long l() throws IOException{
          return sc.nextLong();

        }
        static double d() throws IOException{
          return sc.nextDouble();
        }
        static String s() throws IOException{
          return sc.next();

        }
        static String sL() throws IOException{
          return sc.nextLine();
        }
       static void loop(int[] a) throws IOException{
          for(int j=0;j<a.length;j++){
              a[j]=i();
          }
        }
        static void eloop(int[] a) throws IOException{
          for(int i=1;i<=a.length;i++){
              a[i]=i();
          }
        }
        static void ploop(int[] a)throws IOException{
             for(int j=0;j<a.length;j++){
                System.out.println(a[j]);
             }

        }
        static void eploop(int[] a)throws IOException{
             for(int j=1;j<=a.length;j++){
                System.out.println(a[j]);
             }

        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////

  static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                throw new RuntimeException();
            }
            return str;
        }
    }

 }


/*
Logic is the strongest weapon.
 */

import java.io.*;
import java.util.*;

public class p2 {

    private static InputStream stream;
    private static byte[] buf = new byte[1024];
    private static int curChar;
    private static int numChars;
    private static SpaceCharFilter filter;
    private static PrintWriter pw;
    //private static int N = 1234567;
    //private static final long MOD = (long)1e9 + 7;

    public static boolean is(int[][] man, int i, int j, int n) {
        for (int p = 1; p <= n; p++) {
            if (man[j][p] == 1 && p != j && p != i && man[i][p] != 1) {
                return false;
            }
        }
        return true;
    }

    private static int soln() {
        int n = nI(), m = nI();
        int[][] man = new int[n + 1][n + 1];
        for (int i = 0; i < m; i++) {
            int a = nI(), b = nI();
            man[a][b] = 1;
            man[b][a] = 1;

        }
        /*for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                pw.print(man[i][j] + " ");
            }
            pw.println();
        }*/
        boolean is1 = false;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (man[i][j] == 1) {
                    if (!is(man, i, j, n)) {
                        pw.println("break at i = " + i + " j = " + j);
                        pw.println("NO");
                        is1 = true;
                        break;
                    }
                }
            }
            if (is1) {
                break;
            }
        }
        if (!is1) {
            pw.println("YES");
        }
        return 0;
    }

    public static void main(String[] args) throws FileNotFoundException {
        InputReader(System.in);
        //pw = new PrintWriter(new FileOutputStream("ans.txt"));
        pw = new PrintWriter(System.out);
        soln();
        pw.close();
    }

    /*
     *********************************************************************************************
     */
    public static void InputReader(InputStream stream1) {
        stream = stream1;
    }

    private static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    private static boolean isEndOfLine(int c) {
        return c == '\n' || c == '\r' || c == -1;
    }

    private static int read() {
        if (numChars == -1) {
            throw new InputMismatchException();
        }
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0) {
                return -1;
            }
        }
        return buf[curChar++];
    }

    private static int nI() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9') {
                throw new InputMismatchException();
            }
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    private static long nL() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9') {
                throw new InputMismatchException();
            }
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    private static String nS() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    private static String nLi() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isEndOfLine(c));
        return res.toString();
    }

    private static boolean isSpaceChar(int c) {
        if (filter != null) {
            return filter.isSpaceChar(c);
        }
        return isWhitespace(c);

    }

    private interface SpaceCharFilter {

        public boolean isSpaceChar(int ch);
    }
}


/*
Logic is the strongest weapon.
 */

import java.io.*;
import java.util.*;

public class p2 {

    private static InputStream stream;
    private static byte[] buf = new byte[1024];
    private static int curChar;
    private static int numChars;
    private static SpaceCharFilter filter;
    private static PrintWriter pw;
    //private static int N = 1234567;
    //private static final long MOD = (long)1e9 + 7;

    public static boolean is(int[][] man, int i, int j, int n) {
        for (int p = 1; p <= n; p++) {
            if (man[j][p] == 1 && p != j && p != i && man[i][p] != 1) {
                return false;
            }
        }
        return true;
    }

    private static int soln() {
        int n = nI(), m = nI();
        int[][] man = new int[n + 1][n + 1];
        for (int i = 0; i < m; i++) {
            int a = nI(), b = nI();
            man[a][b] = 1;
            man[b][a] = 1;

        }
        /*for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                pw.print(man[i][j] + " ");
            }
            pw.println();
        }*/
        boolean is1 = false;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (man[i][j] == 1) {
                    if (!is(man, i, j, n)) {
                        //pw.println("break at i = " + i + " j = " + j);
                        pw.println("NO");
                        is1 = true;
                        break;
                    }
                }
            }
            if (is1) {
                break;
            }
        }
        if (!is1) {
            pw.println("YES");
        }
        return 0;
    }

    public static void main(String[] args) throws FileNotFoundException {
        InputReader(System.in);
        //pw = new PrintWriter(new FileOutputStream("ans.txt"));
        pw = new PrintWriter(System.out);
        soln();
        pw.close();
    }

    /*
     *********************************************************************************************
     */
    public static void InputReader(InputStream stream1) {
        stream = stream1;
    }

    private static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    private static boolean isEndOfLine(int c) {
        return c == '\n' || c == '\r' || c == -1;
    }

    private static int read() {
        if (numChars == -1) {
            throw new InputMismatchException();
        }
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0) {
                return -1;
            }
        }
        return buf[curChar++];
    }

    private static int nI() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9') {
                throw new InputMismatchException();
            }
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    private static long nL() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9') {
                throw new InputMismatchException();
            }
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    private static String nS() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    private static String nLi() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isEndOfLine(c));
        return res.toString();
    }

    private static boolean isSpaceChar(int c) {
        if (filter != null) {
            return filter.isSpaceChar(c);
        }
        return isWhitespace(c);

    }

    private interface SpaceCharFilter {

        public boolean isSpaceChar(int ch);
    }
}


/*
Logic is the strongest weapon.
 */

import java.io.*;
import java.util.*;

public class p2 {

    private static InputStream stream;
    private static byte[] buf = new byte[1024];
    private static int curChar;
    private static int numChars;
    private static SpaceCharFilter filter;
    private static PrintWriter pw;
    //private static int N = 1234567;
    //private static final long MOD = (long)1e9 + 7;

    public static boolean is(boolean[][] man, int i, int j, int n) {
        for (int p = 1; p <= n; p++) {
            if (man[j][p] && p != j && p != i && !man[i][p]) {
                return false;
            }
        }
        return true;
    }
    // 1 = true 0 = false
    private static int soln() {
        int n = nI(), m = nI();
        boolean[][] man = new boolean[n + 1][n + 1];
        for (int i = 0; i < m; i++) {
            int a = nI(), b = nI();
            man[a][b] = true;
            man[b][a] = true;

        }
        /*for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                pw.print(man[i][j] + " ");
            }
            pw.println();
        }*/
        boolean is1 = false;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (man[i][j]) {
                    if (!is(man, i, j, n)) {
                        //pw.println("break at i = " + i + " j = " + j);
                        pw.println("NO");
                        is1 = true;
                        break;
                    }
                }
            }
            if (is1) {
                break;
            }
        }
        if (!is1) {
            pw.println("YES");
        }
        return 0;
    }

    public static void main(String[] args) throws FileNotFoundException {
        InputReader(System.in);
        //pw = new PrintWriter(new FileOutputStream("ans.txt"));
        pw = new PrintWriter(System.out);
        soln();
        pw.close();
    }

    /*
     *********************************************************************************************
     */
    public static void InputReader(InputStream stream1) {
        stream = stream1;
    }

    private static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    private static boolean isEndOfLine(int c) {
        return c == '\n' || c == '\r' || c == -1;
    }

    private static int read() {
        if (numChars == -1) {
            throw new InputMismatchException();
        }
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0) {
                return -1;
            }
        }
        return buf[curChar++];
    }

    private static int nI() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9') {
                throw new InputMismatchException();
            }
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    private static long nL() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9') {
                throw new InputMismatchException();
            }
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    private static String nS() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    private static String nLi() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isEndOfLine(c));
        return res.toString();
    }

    private static boolean isSpaceChar(int c) {
        if (filter != null) {
            return filter.isSpaceChar(c);
        }
        return isWhitespace(c);

    }

    private interface SpaceCharFilter {

        public boolean isSpaceChar(int ch);
    }
}


#include<iostream>
using namespace std;

int main(){
int t;
while(t--){
long long int n;
if(n<=2) return 0;
else if(n%2==1){
return ((n-1)/2);
}
else{
return ((n/2)-1);
}
}
}


#include<iostream>
using namespace std;

int main(){
int t;
cin >>t;
while(t--){
long long int n;
cin>>n;
if(n<=2){
n=0;
cout<< n<<endl;
}
else if(n%2==1)
{
n=((n-1)/2);
cout<< n<<endl;
}
else
{
n=((n/2)-1);
cout<< n<<endl;
}
}
}


#include<iostream>
using namespace std;

int main(){
int t;
while(t--){
	long int n;
	if(n<=2){
	return 0;
	}
	else if(n%2==1)
	{
	return ((n-1)/2);
	}
	else
	{
	return ((n/2)-1);
	}
}
}


#include <iostream>
using namespace std;

void solve()
{
	long int n;
	cin >> n;
	long int r = 0;

	if (n == 1 || n == 2)
	{
		cout << "0\n";
		return;
	}

	r = (n / 2) - 1;

	if (n % 2 != 0)
		r++;

	cout << r << "\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	long int t;
	cin >> t;

	while (t--)
		solve();

	return 0;
}


#include <iostream>
using namespace std;

void solve()
{
	long int n;
	cin >> n;
	long int r = 0;
	long int a = n - 1;
	long int b = 1;

	while (a > b)
	{
		r++;
		a--;
		b++;
	}

	cout << r << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	long int t;
	cin >> t;

	while (t--)
		solve();

	return 0;
}


#include <iostream>
using namespace std;

void solve()
{
	int n;
	cin >> n;
	int r = 0;
	int a = n - 1;
	int b = 1;

	while (a > b)
	{
		r++;
		a--;
		b++;
	}

	cout << r << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int t;
	cin >> t;

	while (t--)
		solve();

	return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int t, n;
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		cin >> n;
		if (n % 2 == 0)
			cout << n / 2 - 1 << endl;
		else
			cout << (n - 1) / 2 << endl;
	}
	system("pause");
	return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int t, n;
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		cin >> n;
		cout << (n - 1) / 2 << endl;
	}
	system("pause");
	return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

#define k 10001

int main() {
	int t, n, a[k];
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		cin >> n;
		a[i] = n;
	}
	for (int i = 0; i < t; i++)
	{
		cout << (a[i] - 1) / 2 << endl;
	}
	return 0;
}


#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
    long long n,a,b,i,N,count=0;
    scanf("%lld",&n);
    for(i=0;i<n;i++)
    {
        count=0;
        scanf("%lld",&N);
        a=N-1;
        b=1;
        while(a>b)
        {
            a=a-1;
            b=b+1;
            count++;
        }
        printf("%lld\n",count);
    }

}


#include<stdio.h>
int main()
{
    long long n,i,a,b;
    scanf("%lld",&n);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&a);
        if(a==1)
        {
            printf("0\n");
        }
        else if(a%2==0)
        {
            b=a/2;
            printf("%lld\n",a-b-1);
        }
        else if(a%2!=0)
        {
            b=(a+1)/2;
            printf("%lld\n",a-b);
        }
    }

}


#include <iostream>
using namespace std;

int main(){
 	int n,t;
 	cin>>n;
 	while(n--){
 		cin>>t;
 		if(t%2!=0)cout<<t/2;
 		else cout<<t/2-1;
 		cout<<endl;
	 }
 }


#include <iostream>
using namespace std;

int main(){
 	int n,t;
 	cin>>n;
 	while(n--){
 		cin>>t;
 		if(t%2!=0)cout<<t/2;
 		else cout<<t/2-1;
	 }
 }


#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
using namespace std;

int main()
{
	int t;
	cin >> t;
	for (int I = 0; I < t; I++)
	{
		int n;
		cin >> n;

		if (n <= 2)
			cout << "0" << endl;
		else if (n % 2 == 0)
			cout << n / 2 - 1 << endl;
		else cout << n / 2 << endl;
	}
	getchar();
	getchar();
	getchar();
	getchar();
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
using namespace std;

int main()
{
	int t;
	cin >> t;
	for (int I = 0; I < t; I++)
	{
		int n;
		cin >> n;

		if (n <= 2)
			cout << "0" << endl;
		else cout << n / 2 << endl;
	}
	getchar();
	getchar();
	getchar();
	getchar();
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
using namespace std;

int main()
{
	int t;
	cin >> t;
	for (int I = 0; I < t; I++)
	{
		int n;
		cin >> n;

		if (n <= 2)
			cout << "0";
		else cout << n / 2;
	}
	getchar();
	getchar();
	getchar();
	getchar();
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

int main() {
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		if (n < 3) {
			cout << 0;
		}
		if (n == 3) {
			cout << 1;
		}
		if (n > 3) {
			cout << n / 2 - 1;
		}
	}
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

int main() {
	int t;
	while (t--) {
		int n;
		cin >> n;
		if (n < 3) {
			cout << 0;
		}
		if (n == 3) {
			cout << 1;
		}
		if (n > 3) {
			cout << n / 2 - 1;
		}
	}
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

int main() {
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		cout << (n - 1) / 2 << endl;
		}
}


#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;
    for (int i = 1; i <= t; i++)
    {
        int n;
        cin >> n;
        if (n == 1 || n == 2)
        {
            cout << 0 << endl;
        }
        else
        {
            if (n % 2 == 0)
            {
                cout << (n / 2) - 1 << endl;
            }
            else
            {
                cout << (n / 2) << endl;
            }
        }
    }
}


#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;
    for (int i = 1; i <= t; i++)
    {
        int n;
        cin >> n;
        if (n == 1 || n == 2)
        {
            cout << 0 << endl;
        }
        else
        {
            cout << (n / 2) << endl;
        }
    }
}


#include<iostream>
#include<set>

using namespace std;
int M[100][100];

int main()
{
	int T,N;
	cin >> T;
	for (int t = 1; t <= T; t++) {
		cin >> N;
		for (int i = 0; i < N; i++)
			for (int j = 0; j < N; j++)
				cin >> M[i][j];
		int k = 0, r = 0, c = 0;
		for (int i = 0; i < N; i++)
			k = k + M[i][i];
		for (int i = 0; i < N; i++) {
			set<int>s;
			for (int j = 0; j < N; j++)
				s.insert(M[i][j]);
			r = r + (s.size() != N);

		}

		for (int j = 0; j < N; j++) {
			set<int>s;
			for (int i = 0; i < N; i++)
				s.insert(M[i][j]);
			c = c + (s.size() != N);

		}

		cout << "Case #" << t << ": " << k << " " << r << " " << c << endl;
	}
	return 0;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define rep(i,a,b) for(auto i=(a);i<=(b);++i)
#define dep(i,a,b) for(auto i=(a);i>=(b);--i)
#define pb push_back
typedef long long ll;
const int maxn=(int)1e6+100;
const int mod=(int)1e9+7;
void solve(){
    ll n;scanf("%lld",&n);
    printf("%lld\n",n/2-(n%2==0));
}
int main(){
    int T;cin>>T;
    while(T--) solve();
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(auto i=(a);i<=(b);++i)
#define dep(i,a,b) for(auto i=(a);i>=(b);--i)
#define pb push_back
typedef long long ll;
const int maxn=(int)1e6+100;
const int mod=(int)1e9+7;
void solve(){
    ll n;scanf("%lld",&n);
    printf("%lld\n",n/2-(n%2==0));
}
int main(){
    int T;cin>>T;
    while(T--) solve();
}


#include<iostream>
using namespace std;

void main() {

	int numberline;
	cin >> numberline;
	int tmpline = 0;

	while(tmpline < numberline){
			int in, result;
			int ultimate;

			cin >> in;

		if (in < 3) {
			cout << "0" << endl;
		}
		else {
			result = in / 2;
			ultimate = in - result - 1;

			cout << "out = "<<ultimate<<endl;
		}

		tmpline++;
	}

}


#include<iostream>
using namespace std;

void main() {

	int numberline;
	cin >> numberline;
	int tmpline = 0;

	while(tmpline < numberline){
			int in, result;
			int ultimate;

			cin >> in;

		if (in < 3) {
			cout << "0" << endl;
		}
		else {
			result = in / 2;
			ultimate = in - result - 1;

			cout << ultimate<<endl;
		}

		tmpline++;
	}

}


#include <iostream>
int main()
{
    long long t;
    std::cin >> t;
    while( t-- )
    {
        long long n;
        std::cin>>n;
        long long ans = n/2;
        if(n%2==1)
            ans+=1;
        std::cout<<ans<<std::endl;
    }
    return 0;
}


#include <iostream>
int main()
{
    long long t;
    std::cin >> t;
    while( t-- )
    {
        long long n;
        std::cin>>n;
        std::cout<<(n-1)/2<<std::endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main() {
       int c;
       cin>>c;
       for(int i=0;i<c;i++){
           int k;
           cin>>k;
           if(k<3){
           cout<<0<<endl;}
           else if (k%2==1){
               int j;
               j=k/2;
               cout<<j<<endl;
           }
           else{
               int m;
               m=(k/2)-1;
               cout<<m<<endl;
           }

       }
   return 0;
}


#include <iostream>
using namespace std;
int main() {
       int c;
       cin>>c;
       for(int i=0;i<c;i++){
           int k;
           cin>>k;
           int j=k/2;
           cout<<j<<endl;
       }
   return 0;
}


#include<iostream>
using namespace std;
int main()
{int n,t;
cin>>t;
for(int i=0;i<t;i++)
{
cin>>n;
if(n%2==0)
cout<<(n-2)/2;
else
cout<<(n-1)/2;
}
return 0;
}


#include<iostream>
using namespace std;
int main()
{int n,t;
cin>>t;
for(int i=0;i<t;i++)
{
cin>>n;
if(n%2==0)
cout<<(n-2)/2<<endl;
else
cout<<(n-1)/2<<endl;
}
return 0;
}


#include<iostream>
using namespace std;
int main()
{int n,t;
cout<<"enter t";
cin>>t;
for(int i=0;i<t;i++)
{cout<<"enter n";
cin>>n;
if(n%2==0)
cout<<(n-2)/2;
else
cout<<(n-1)/2;
}
return 0;
}


include<iostream>
using namespace std;
int main()
{int n,t;
cin>>t;
for(int i=0;i<t;i++)
{
cin>>n;
if(n%2==0)
cout<<(n-2)/2;
else
cout<<(n-1)/2;
}
return 0;
}


#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main()
{
	int size;
	cin>>size;

	while(size>0)
	{
		int c=0;
		int u;
		cin>>u;
		int i=u-1;
		int y=1;
		while (true)
		{

			if(i>y)
			{
				c++;
				i--;
				y++;
			}
			else
				break;

		}

		cout<<c<<endl;
		size--;
	}

//	system("pause");
	return 0;
}


#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main()
{
	int size;
	cin>>size;

	while(size>0)
	{

		int u;
		cin>>u;
		if(u%2==0)
			cout<<u/2-1;
		else
			cout<<u/2;
		cout<<endl;
		size--;
	}

//	system("pause");
	return 0;
}


#include<iostream>
using namespace std;
int main(){
    long long int  t;
    std::cin>>t;
    while(t--){
        long long int n;
        std::cin>>n;
        if(n%2!=0){
            cout<<(n/2)<<endl;
        }else{
            cout<<(n/2 - 1)<<endl;
        }

        }
    }


#include<iostream>
using namespace std;
int main(){
	long long int t;
	cin>>t;
	long long int n[t];
	for(int z=0;z<t;z++){
		cin>>n[z];
	}
	for(int z=0;z<t;z++){
		long long int temp;
		temp = n[z];
			if(temp%2 == 0){
				cout<<(temp/2)-1<<endl;
			}else{
				cout<<(temp/2)<<endl;
			}
		}
	}


#include<iostream>
using namespace std;
int main(){
	long long int t;
	cin>>t;
	long long int n[t];
	for(int z=0;z<t;z++){
		cin>>n[z];
		long long int temp;
		temp = n[z];
			if(temp%2 == 0){
				cout<<(temp/2)-1<<endl;
			}else{
				cout<<(temp/2)<<endl;
			}
		}
	}


#include<iostream>
using namespace std;
int main(){
	long long int t;
	cin>>t;
	long long int n[t];
	for(int z=0;z<t;z++){
		cin>>n[z];
	}
	for(int z=0;z<t;z++){
		long int temp;
		temp = n[z];
			if(temp%2 == 0){
				cout<<(temp/2)-1<<endl;
			}else{
				cout<<(temp/2)<<endl;
			}
		}
	}


#include<iostream>
using namespace std;
int main(){
	int t;
	cin>>t;
	long int n[t];
	for(int z=0;z<t;z++){
		cin>>n[z];
	}
	for(int z=0;z<t;z++){
		long int temp;
		temp = n[z];
			if(temp%2 == 0){
				cout<<(temp/2)-1<<endl;
			}else{
				cout<<(temp/2)<<endl;
			}
		}
	}


#include<iostream>
using namespace std;

int main()
{
  long long int n;
  cin>>n;
  for(long long int i=1;i<=n;i++)
  {
     long long int candies;
     cin>>candies;
     if(candies%2==0)
     {
        cout<<candies/2-1<<endl;
     }else{
        cout<<candies/2<<endl;
     }
  }

  return 0;
}


#include<iostream>
using namespace std;

int main()
{
  long long int n;
  cin>>n;
  for(long long int i=1;i<=6;i++)
  {
     long long int candies;
     cin>>candies;
     if(candies%2==0)
     {
        cout<<candies/2-1<<endl;
     }else{
        cout<<candies/2<<endl;
     }
  }

  return 0;
}


#include<iostream>
using namespace std;

int main()
{
  long int n;
  cin>>n;
  for(long int i=1;i<=6;i++)
  {
     long int candies;
     cin>>candies;
     if(candies%2==0)
     {
        cout<<candies/2-1<<endl;
     }else{
        cout<<candies/2<<endl;
     }
  }

  return 0;
}


#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
    long int n;
    cin>>n;
    if(n%2==0)
    {
        cout<<(n/2)-1<<endl;
    }
    else{
        cout<<n/2<<endl;
    }
}
return 0;
}


#include<iostream>
using namespace std;
int main(){
	int n,a[10000];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		if(a[i]%2==0) cout<<a[i]/2-1<<endl;
		if(a[i]%2!=0) cout<<(a[i]-1)/2<<endl;
		}
	}


#include<iostream>
using namespace std;
int main(){
	int n,a[1000];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		if(a[i]%2==0) cout<<a[i]/2-1<<endl;
		if(a[i]%2!=0) cout<<(a[i]-1)/2<<endl;
		}
	}


#include <iostream>

using namespace std;

int main() {
	int t; cin >> t;

	while (t--) {
		int n; cin >> n;
		cout << (n + 1) / 2 - (n & 1) << "\n";
	}
	return 0;
}


#include <iostream>

using namespace std;

int main() {
	int t; cin >> t;

	while (t--) {
		int n; cin >> n;
		cout << (n - 1) / 2 << "\n";
	}
	return 0;
}


#include<iostream>
using namespace std;

	int main() {
		ios::sync_with_stdio(0);
		cin.tie(0);
		int t;
		cin >> t;
		while(t--) {
		int n;
		cin >> n;
		cout << (n-1)/2 << "\n";
	}
	return 0;
}


/*There are two sisters Alice and Betty. You have n candies. You want to distribute these n candies between two sisters in such a way that:

Alice will get a (a>0) candies;
Betty will get b (b>0) candies;
each sister will get some integer number of candies;
Alice will get a greater amount of candies than Betty (i.e. a>b);
all the candies will be given to one of two sisters (i.e. a+b=n).
Your task is to calculate the number of ways to distribute exactly n candies between sisters in a way described above. Candies are indistinguishable.

Formally, find the number of ways to represent n as the sum of n=a+b, where a and b are positive integers and a>b.

You have to answer t independent test cases.
*/
#include<iostream>
using namespace std;

	int main() {
		int t,a,b;
		cin >> t;
		while(t--) {
			int n;
			cin >> n;
			cout << (n-1)/2;
	}
	return 0;
}


#include <iostream>
using namespace std;
void main{

long t;
cin>>t;
long *a=new long[t];
for(long i=0;i<t;i++)
cin>>a[i];
for(long j=0;j<t;j++){
if(a[j]%2==0)
cout<<(a[j]/2)-1<<endl;
else
cout<<a[j]/2<<endl;}}


#include <iostream>
using namespace std;
void main{

long t;
cin>>t;
long *a=new long[t];
for(long i=0;i<t;i++)
cin>>a[i];
for(long j=0;j<t;j++){
if(a[i]%2==0)
cout<<(a[j]\2)-1;
else
cout<<a[j]\2;}}


#include <iostream>
#include<algorithm>
using namespace std;
#include<iterator>
int main(){
	int i,d[i],a,b,c;
	for(i=0;i<4;i++){
		cin>>d[i];
	}
	sort(d,d+4);
	c=d[3]-d[0];
	b=d[3]-d[1];
	a=d[3]-d[2];
	cout<<c<<b<<a;

}


#include<iostream>
using namespace std;
int main(){
	int a;
	cin>>a;
	while(a--){
		int n;
		cin>>n;
		if(n=1&&n==2){
			cout<<"0"<<endl;}
			else{
				if(n%2==0){
					cout<<n/2-1<<endl;}
					else{
						cout<<n-1/2<<endl;
					}
				}
			}
		}


#include<iostream>
using namespace std;
int main(){
	int a;
	cin>>a;
	while(a--){
		int n;
		cin>>n;
		if(n==1&&n==2){
			cout<<"0"<<endl;}
			else{
				if(n%2==0){
					cout<<n/2-1<<endl;}
					else{
						cout<<n-1/2<<endl;
					}
				}
			}
		}


#include<iostream>
using namespace std;
int main(){
	int a;
	cin>>a;
	while(a--){
		int n;
		cin>>n;
		if(n==1&&n==2){
			cout<<"0"<<endl;}
			else{
				if(n%2==0){
					cout<<n/2-1<<endl;}
					else{
						cout<<n/2-1/2<<endl;
					}
				}
			}
		}


#include<iostream>
#define long long ll
using namespace std;
int main(){
            ll t;
          cin>>t;
          while(t--){
                 ll n;
                 cin>>n;
                 ll m=(n-1)/2;
                 cout<<m<<endl;
          }
          return 0;
}


#include<iostream>
using namespace std;
int main(){
            long long t;
          cin>>t;
          while(t--){
                 long long n;
                 cin>>n;
                 long long m=(n-1)/2;
                 cout<<m<<endl;
          }
          return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
//#include<utility>
using namespace std;
int main(){
        long long n;
       cin>>n;
       while(n--){
                 long long m,count=0;
                 cin>>m;
                 long long a=m-1,b=1;
                 while(a>b){
                           a--,b++;
                           count++;
                 }
               cout<<count<<endl;
       }
          return 0;
}


#include<stdio.h>
int main()
{
    int t,n,i;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {
        scanf("%d",&n);
        if(n%2==1)
        {
            printf("%d",n/2);
            continue;
        }
        if(n==1)
           {
            printf("0");
            continue;
           }
        if(n%2==0)
        { printf("%d",(n/2)-1);
        continue;}
    }
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<conio.h>
arr(int);
void main()
{
    long a;
    cout<<"enter number of test cases";
    cin>>a;
    arr(a);
    getch();
}
arr(int b)
{
    int i,arry[b],s;
    for(i=1;i<=b;i++)
    {
        cin>>arr[i];
    }
    for(i=1;i<=b;i++)
    {
        if(arry[i]%2==0)
        {
            s=(arry[i]%2)-1;
        }
        else
        {
            s=(arry[i]-1)/2;
        }
        printf("%d",s);
    }
}


#include<stdio.h>
#include<conio.h>
void main()
{
    int a;
    scanf("%d",&a);
    int arr[10001];
    int i,s;
    for(i=1;i<=a;i++)
    {
        scanf("%d",&arr[i]);
    }
    for (i=1;i<=a;i++)
    {
        if(arr[i]%2==0)
        {
            s=(arr[i]/2)-1;
        }
        else
        {
            s=(arr[i]-1)/2;
        }
        printf("\n %d",s);
    }
}


#include<stdio.h>
#include<conio.h>
void main()
{
    int a;
    scanf("%d",&a);
    int arr[10000];
    int i,s;
    for(i=1;i<=a;i++)
    {
        scanf("%d",&arr[i]);
    }
    for (i=1;i<=a;i++)
    {
        if(arr[i]%2==0)
        {
            s=(arr[i]/2)-1;
        }
        else
        {
            s=(arr[i]-1)/2;
        }
        printf("%d",s);
    }
}


#include<stdio.h>
#include<conio.h>
void arr(int);
void main()
{
    long a;
    printf("enter number of test cases");
    scanf("%d",&a);
    arr(a);
    getch();
}
void arr(int b)
{
    int i,arry[10000],s;
    for(i=1;i<=b;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(i=1;i<=b;i++)
    {
        if(arry[i]%2==0)
        {
            s=(arry[i]%2)-1;
        }
        else
        {
            s=(arry[i]-1)/2;
        }
        printf("%d",s);
    }
}


#include<stdio.h>
#include<conio.h>
void arr(int);
void main()
{
    long a;
    printf("enter number of test cases");
    scanf("%d",&a)
    arr(a);
    getch();
}
void arr(int b)
{
    int i,arry[b],s;
    for(i=1;i<=b;i++)
    {
        cin>>arry[i];
    }
    for(i=1;i<=b;i++)
    {
        if(arry[i]%2==0)
        {
            s=(arry[i]%2)-1;
        }
        else
        {
            s=(arry[i]-1)/2;
        }
        printf("%d",s);
    }
}


#include<stdio.h>
#include<conio.h>
void main()
{
    int a;
    scanf("%d",&a);
    int arr[10000];
    long i,s;
    for(i=1;i<=a;i++)
    {
        scanf("%d",&arr[i]);
    }
    for (i=1;i<=a;i++)
    {
        if(arr[i]%2==0)
        {
            s=(arr[i]/2)-1;
        }
        else
        {
            s=(arr[i]-1)/2;
        }
        printf("%d",s);
    }
}


#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void arr(int);
void main()
{
    long a;
    printf("enter number of test cases");
    scanf("%d",&a);
    arr(a);
    getch();
}
void arr(int b)
{
    int i,arry[b],s;
    for(i=1;i<=b;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(i=1;i<=b;i++)
    {
        if(arry[i]%2==0)
        {
            s=(arry[i]%2)-1;
        }
        else
        {
            s=(arry[i]-1)/2;
        }
        printf("%d",s);
    }
}


#include<iostream.h>
#include<stdio.h>
#include<conio.h>
arr(int);
void main()
{
    long a;
    cout<<"enter number of test cases";
    cin>>a;
    arr(a);
    getch();
}
arr(int b)
{
    int i,arry[b],s;
    for(i=1;i<=b;i++)
    {
        cin>>arr[i];
    }
    for(i=1;i<=b;i++)
    {
        if(arry[i]%2==0)
        {
            s=(arry[i]%2)-1;
        }
        else
        {
            s=(arry[i]-1)/2;
        }
        printf("%d",s);
    }
}


#include<stdio.h>
#include<conio.h>
void arr(int);
void main()
{
    long a;
    printf("enter number of test cases");
    scanf("%d",&a);
    arr(a);
    getch();
}
void arr(int b)
{
    int i,arry[b],s;
    for(i=1;i<=b;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(i=1;i<=b;i++)
    {
        if(arry[i]%2==0)
        {
            s=(arry[i]%2)-1;
        }
        else
        {
            s=(arry[i]-1)/2;
        }
        printf("%d",s);
    }
}


#include<stdio.h>
#include<conio.h>
void main()
{
    int a;
    scanf("%d",&a);
    int arr[10000];
    int i,s;
    for(i=1;i<=a;i++)
    {
        scanf("%d",&arr[i]);
    }
    for (i=1;i<=a;i++)
    {
        if(arr[i]%2==0)
        {
            s=(arr[i]/2)-1;
        }
        else
        {
            s=(arr[i]-1)/2;
        }
        printf("\n %d",s);
    }
    getch();
}


#include<stdio.h>
#include<conio.h>
void main()
{
    int a;
    scanf("%d",&a);
    int arr[10000];
    long i,s;
    for(i=1;i<=a;i++)
    {
        scanf("%d",&arr[i]);
    }
    for (i=1;i<=a;i++)
    {
        if(arr[i]%2==0)
        {
            s=(arr[i]/2)-1;
        }
        else
        {
            s=(arr[i]-1)/2;
        }
        printf("\n %d",s);
    }
}


#include<stdio.h>
#include<conio.h>
void main()
{
    int a;
    scanf("%d",&a);
    int arr[10000];
    int i,s;
    for(i=1;i<=a;i++)
    {
        scanf("%d",&arr[i]);
    }
    for (i=1;i<=a;i++)
    {
        if(arr[i]%2==0)
        {
            s=(arr[i]/2)-1;
        }
        else
        {
            s=(arr[i]-1)/2;
        }
        printf("%d",s);
    }
    getch();
}


#include<iostream>
#include<vector>
using namespace std;
int main() {
	vector <int> f;
	int a, n, t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		cin >> n;
		f.push_back(n);
	}
	for (int i = 0; i < t; i++) {
		if (f[i] > 2) {
			f[i] % 2 == 0 ? a = f[i] / 2 -1 : a = f[i] / 2;
			cout << a;
		}
		else { cout << 0; }
	}

	return 0;
}


#include<iostream>
#include<vector>
using namespace std;
int main() {
	vector <int> f;
	int a, n, t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		cin >> n;
		f.push_back(n);
	}
	for (int i = 0; i < t; i++) {
		if (f[i] > 2) {
			f[i] % 2 == 0 ? a = f[i] / 2 -1 : a = f[i] / 2;
			cout << a << endl;
		}
		else { cout << 0<<endl; }
	}

	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    long t;
    cin>>t;
    while(t--)
    {
        long n;
        cin>>n;
        if((n>=3)&&(n%2==0))
        {
            cout<<(n/2)-1<<endl;
        }
        else if((n>=3)&&n%2==1)
        {
            cout<<n/2<<endl;
        }
        else
        {
            cout<<"0"<<endl;
        }
    }
}


#include<iostream>
using namespace std;
int main()
{
    long t;
    cin>>t;
    while(t--)
    {
        long n;
        cin>>n;
        if((n>3)&&(n%2==0))
        {
            cout<<(n/2)-1<<endl;
        }
        else if((n>3)&&n%2==1)
        {
            cout<<n/2<<endl;
        }
        else
        {
            cout<<"0"<<endl;
        }
    }
}


#include<iostream>
using namespace std
int main()
{
int t;
cin>>t;
while(t--)
{
    long int n;
    cin>>n;
    if(n%2==0)
    {
        cout<<(n/2)-1<<endl;
    }
    else{
        cout<<n/2<<endl;
    }
}
return 0;
}


int t;
cin>>t;
while(t--)
{
    long int n;
    if(n%2==0)
    {
        cout<<(n/2)-1<<endl;
    }
    else{
        cout<<n/2<<endl;
    }
}


int t;
cin>>t;
while(t--)
{
    long int n;
    cin>>n;
    if(n%2==0)
    {
        cout<<(n/2)-1<<endl;
    }
    else{
        cout<<n/2<<endl;
    }
}


#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
    long int n;
    cin>>n;
    if(n%2==0)
    {
        cout<<(n/2)-1<<endl;
    }
    else{
        cout<<n/2<<endl;
    }
}
return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int n, in, ou;
	cin >> n;
	while (n--)
	{
		cin >> in;
		if (in < 3)
			ou = 0;
		else
		{
			if (in % 2 == 0)
				ou = in / 2 - 1;
			else
				ou = in / 2;
		}
		cout << ou << endl;
	}
	return 0;

}


#include <iostream>
using namespace std;

int main()
{
	int n, in[1000], a = 0, b = 0, c , ou[1000];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> in[i];
		a = in[i] - 1;
		b = 1;
		c++;
		if (in[i] == 1)
			c = 0;
		for (int j = 0; a > 0; j++)
	    {

			a--;
			b++;
			c++;

	    }
		ou[i] = c;
	}

	for (int i = 0; i < n; i++)
		cout << ou[i];

	return 0;

}


#include<iostream>
using namespace std;

int main(){
	int T, num, ans;
	cin >> T;
	for(int i=0; i<T; i++){
		cin >> num;
		if(num%2==0 && num/2>1) ans=num/2-1;
		else if(num%2!=0) ans=num/2;
		else if(num==1 || num==0) ans=0;
		cout << ans << "\n";
	}
	return 0;
}


#include<iostream>
using namespace std;

int main(){
	long T, num, ans;
	cin >> T;
	for(int i=0; i<T; i++){
		cin >> num;
		if(num%2==0) ans=num/2-1;
		else if(num%2!=0) ans=num/2;
		else if(num==0) ans=0;
		cout << ans << "\n";
	}
	return 0;
}


#include<iostream>
using namespace std;

int main(){
	long T, num, ans;
	cin >> T;
	for(int i=0; i<T; i++){
		cin >> num;
		if(num%2==0 && num/2>1) ans=num/2-1;
		else if(num%2!=0) ans=num/2;
		else if(num==1 || num==0) ans=0;
		cout << ans << "\n";
	}
	return 0;
}


/* Task description
https://codeforces.com/problemset/problem/1335/A
*/

#include <iostream>

int main()
{
    int cases, candles, ans;
    std::cin >> cases;

    for (int i = 0; i < cases; ++i)
    {
        std::cin >> candles;

        ans = 0;
        if (candles > 2)
            ans = (candles - 1) / 2;
        std::cout << ans;
    }
}


/* Task description
https://codeforces.com/problemset/problem/1335/A
*/

#include <iostream>

int main()
{
    int cases, candles, ans;
    std::cin >> cases;

    for (int i = 0; i < cases; ++i)
    {
        std::cin >> candles;

        ans = 0;
        if (candles > 2)
            ans = (candles - 1) / 2;
        std::cout << ans << std::endl;
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main() {
	int t ,ans ,n;
	cin >> t;
	while (t--) {
	    ans = 0;
		cin >> n;
		for(int i = 1, j = n-1; i < j; i++ ,j--){
		    ans++;
		}
		cout << ans << endl;
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main() {
	int t ,ans ,n;
	cin >> t;
	while (t--) {
	    ans = 0;
		cin >> n;
		if(n < 3) cout << 0 << endl;
		else cout << (n+1)/2-1 << endl;
	}

	return 0;
}


#include<iostream>
using namespace std;

int main()
{
   int s,t;
    cin>>t;
    for(s=1;s<=t;s++){

   long long int p;
      cin>>p;
      if(p%2==0){
            cout<<p/2-1<<endl;
        }
        else
            cout<<p/2<<endl;

}
    return 0;

}


#include<iostream>
using namespace std;

int main()
{
   int s,t;
    cin>>t;
    for(s=1;s<=t;s++){

   long long int p,q,a=0;
      cin>>p;
        q=p;
     while(p>q/2){
       p=p-1;
        a++;
    }

    cout<<a-1<<endl;

}
    return 0;

}


#include <iostream>
using namespace std;
int main()
{
    int n, x;
    cin >> n;
    for (int i = 0;i < n;i++) {
        cin >> x;
        if (x == 2 || x == 1)
            cout << "0";

        else
            cout << (x - 1) / 2 << endl;

    }
return 0;
}


#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back

using namespace std;
typedef long long ll;

const int N = 5e5+5;

pair<vector<int>, int> lst[N];
ll val[N];
int par[N];

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t; cin >> t;
	while(t--){
		int n, m; cin >> n >> m;
		for(int i = 1; i <= n; ++i){
			cin >> val[i];
			lst[i].S = i;
			lst[i].F.clear();
			par[i] = i;
		}

		for(int i = 0; i < m; ++i){
			int a, b; cin >> a >> b;
			lst[b].F.pb(a);
		}

		for(int i = 1; i <= n; ++i){
			sort(lst[i].F.begin(), lst[i].F.end());
		}

		sort(lst + 1, lst + n + 1);

		for(int i = 1; i <= n; ++i){
			if(lst[i].F.size() == 0){
				par[i] = -1;
				continue;
			}
			if(i > 1 && lst[i].F == lst[i - 1].F){
				par[lst[i].S] = par[lst[i - 1].S];
				val[par[lst[i].S]] += val[lst[i].S];
			}
		}

		ll gcd = 0;
		for(int i = 1; i <= n; ++i){
			if(par[i] == i){
				gcd = __gcd(gcd, val[i]);
			}
		}
		cout << gcd << endl;
	}
}


#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back

using namespace std;
typedef long long ll;

const int N = 5e5+5;

pair<vector<int>, int> lst[N];
ll val[N];
int par[N];

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t; cin >> t;
	while(t--){
		int n, m; cin >> n >> m;
		for(int i = 1; i <= n; ++i){
			cin >> val[i];
			lst[i].S = i;
			lst[i].F.clear();
			par[i] = i;
		}

		for(int i = 0; i < m; ++i){
			int a, b; cin >> a >> b;
			lst[b].F.pb(a);
		}

		for(int i = 1; i <= n; ++i){
			sort(lst[i].F.begin(), lst[i].F.end());
		}

		sort(lst + 1, lst + n + 1);

		for(int i = 1; i <= n; ++i){
			if(i > 1 && lst[i].F == lst[i - 1].F){
				par[lst[i].S] = par[lst[i - 1].S];
				val[par[lst[i].S]] += val[lst[i].S];
			}
		}

		ll gcd = 0;
		for(int i = 1; i <= n; ++i){
			if(par[i] == i){
				gcd = __gcd(gcd, val[i]);
			}
		}
		cout << gcd << endl;
	}
}


#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back

using namespace std;
typedef long long ll;

const int N = 5e5+5;

vector<int> lst[N];
ll val[N];
int par[N];

map<ll, ll> sum;

int main(){
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t; scanf("%d", &t);
	while(t--){
		int n, m; scanf("%d%d", &n, &m);
		for(int i = 1; i <= n; ++i){
//			cin >> val[i];
			scanf("%lld", &val[i]);
			par[i] = i;
			lst[i].clear();
		}

		for(int i = 0; i < m; ++i){
			int a, b; scanf("%d %d", &a, &b);
			lst[b].pb(a);
		}

		for(int i = 1; i <= n; ++i){
			if(lst[i].size() == 0)continue;
			sort(lst[i].begin(), lst[i].end());
			ll hash = 0;
			for(int j = 0; j < lst[i].size(); ++j){
				hash *= n + 1;
				hash += lst[i][j];
			}

			sum[hash] += val[i];
		}
		ll gcd = 0;
		for(auto x : sum){
//			cout << x.S << endl;
			gcd = __gcd(gcd, x.S);
		}
		printf("%lld\n", gcd);
		sum.clear();
	}
}


#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back

using namespace std;
typedef long long ll;

const int N = 5e5+5;

vector<int> lst[N];
ll val[N];
int par[N];

map<ll, ll> sum;

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t; cin >> t;
	while(t--){
		int n, m; cin >> n >> m;
		for(int i = 1; i <= n; ++i){
			cin >> val[i];
			par[i] = i;
			lst[i].clear();
		}

		for(int i = 0; i < m; ++i){
			int a, b; cin >> a >> b;
			lst[b].pb(a);
		}

		for(int i = 1; i <= n; ++i){
			if(lst[i].size() == 0)continue;
			sort(lst[i].begin(), lst[i].end());
			ll hash = 0;
			for(int j = 0; j < lst[i].size(); ++j){
				hash *= 524287;
				hash += lst[i][j];
			}
//			cout << i << " -> " << hash << endl;
			sum[hash] += val[i];
		}
		ll gcd = 0;
		for(auto x : sum){
//			cout << x.S << endl;
			gcd = __gcd(gcd, x.S);
		}
		cout << gcd << endl;
		sum.clear();
	}
}


#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back

using namespace std;
typedef long long ll;

const int N = 5e5+5;

vector<int> lst[N];
ll val[N];
int par[N];

map<ll, ll> sum;

int main(){
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t; scanf("%d", &t);
	while(t--){
		int n, m; scanf("%d%d", &n, &m);
		for(int i = 1; i <= n; ++i){
			cin >> val[i];
			scanf("%d", val + i);
			par[i] = i;
			lst[i].clear();
		}

		for(int i = 0; i < m; ++i){
			int a, b; scanf("%d %d", &a, &b);
			lst[b].pb(a);
		}

		for(int i = 1; i <= n; ++i){
			if(lst[i].size() == 0)continue;
			sort(lst[i].begin(), lst[i].end());
			ll hash = 0;
			for(int j = 0; j < lst[i].size(); ++j){
				hash *= 524287;
				hash += lst[i][j];
			}
//			cout << i << " -> " << hash << endl;
			sum[hash] += val[i];
		}
		ll gcd = 0;
		for(auto x : sum){
//			cout << x.S << endl;
			gcd = __gcd(gcd, x.S);
		}
		printf("%lld\n", gcd);
		sum.clear();
	}
}


#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back

using namespace std;
typedef long long ll;

const int N = 5e5+5;

vector<int> lst[N];
ll val[N];
int par[N];

map<ll, ll> sum;

int main(){
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t; scanf("%d", &t);
	while(t--){
		int n, m; scanf("%d%d", &n, &m);
		for(int i = 1; i <= n; ++i){
//			cin >> val[i];
			scanf("%lld", &val[i]);
			par[i] = i;
			lst[i].clear();
		}

		for(int i = 0; i < m; ++i){
			int a, b; scanf("%d %d", &a, &b);
			lst[b].pb(a);
		}

		for(int i = 1; i <= n; ++i){
			if(lst[i].size() == 0)continue;
			sort(lst[i].begin(), lst[i].end());
			ll hash = 0;
			for(int j = 0; j < lst[i].size(); ++j){
				hash *= 524287LL;
				hash += lst[i][j];
			}

			sum[hash] += val[i];
		}
		ll gcd = 0;
		for(auto x : sum){
//			cout << x.S << endl;
			gcd = __gcd(gcd, x.S);
		}
		printf("%lld\n", gcd);
		sum.clear();
	}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
//const int MOD = 1e9+9 + 1e13;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> t;
	while (t--){
	   int MOD = rand();
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()%120328432710;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] = (d[b]+F[a])%MOD;
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]+=c[i];
	}
	long long gcd = 0;
	if (mp.empty())
	cout <<'w';
	else
	{
	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
	}
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
//const int MOD = 1e9+9 + 1e13;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> t;
	while (t--){
	   int MOD = rand();
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] += F[a];
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]+=c[i];
	}
	long long gcd = 0;
	if (mp.empty())
	cout <<'w';
	else
	{
	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
	}
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
const int MOD = 1e9+9;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> t;
	while (t--){
	//   int MOD = rand();
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] = (d[b]+F[a])%MOD;
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]=(mp[d[i]] + c[i])%MOD;
	}
	long long gcd = 0;
	if (mp.empty())
	cout <<'w';
	else
	{
	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
	}
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
const int MOD = 1e9+9 + 134734675425;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	srand (time(NULL));
//	cout << rand();
//	return 0;
	cin >> t;
	while (t--){
	  // int MOD = rand()%127342174301;
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] = (d[b]+F[a]);
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]=(mp[d[i]] + c[i]);
	}
	long long gcd = 0;

	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
const int MOD = 1e9+9 + 134725634675425;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	srand (time(NULL));
//	cout << rand();
//	return 0;
	cin >> t;
	while (t--){
	  // int MOD = rand()%127342174301;
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()*rand();//%121454636546733%MOD;
		if (F[i] == 0)
		    F[i] = rand();
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] = (d[b]+F[a]);
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]=(mp[d[i]] + c[i]);
	}
	long long gcd = 0;

	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
const int MOD = 1e9+9 + 1e13;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> t;
	while (t--){
		map<long long,int> mp;
		mp.clear();
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = abs(rand()%MOD);
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] += F[a];
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]+=c[i];
	}
	long long gcd = 0;

	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
const int MOD = 1e9+9;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	srand (time(NULL));
//	cout << rand();
//	return 0;
	cin >> t;
	while (t--){
	  // int MOD = rand()%127342174301;
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] = (d[b]+F[a]);
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]=(mp[d[i]] + c[i]);
	}
	long long gcd = 0;

	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
const int MOD = 1e9+9;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	srand (time(NULL));
//	cout << rand();
//	return 0;
	cin >> t;
	while (t--){
	   int MOD = rand()%127342174301;
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] = (d[b]+F[a])%MOD;
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]=(mp[d[i]] + c[i]);
	}
	long long gcd = 0;
	if (mp.empty())
	cout <<'w';
	else
	{
	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
	}
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
//const int MOD = 1e9+9 + 1e13;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> t;
	while (t--){
	   int MOD = rand()%1e12;
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] += F[a];
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]+=c[i];
	}
	long long gcd = 0;
	if (mp.empty())
	cout <<'w';
	else
	{
	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
	}
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
const int MOD = 1e9+9;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> t;
	while (t--){
	//   int MOD = rand();
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] = (d[b]+F[a])%MOD;
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]=(mp[d[i]] + c[i]);
	}
	long long gcd = 0;
	if (mp.empty())
	cout <<'w';
	else
	{
	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
	}
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
//const int MOD = 1e9+9 + 1e13;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> t;
	while (t--){
	   int MOD = rand()%120328432710;
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] = (d[b]+F[a])%MOD;
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]+=c[i];
	}
	long long gcd = 0;
	if (mp.empty())
	cout <<'w';
	else
	{
	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
	}
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
const int MOD = 1e9+9 + 1e13;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> t;
	while (t--){
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] += F[a];
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]+=c[i];
	}
	long long gcd = 0;
	if (mp.empty())
	cout <<'w';
	else
	{
	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
	}
}
}


#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ll long long
using namespace std;
const int N = 2e5+5;
int n,m,k,t,a,b;
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> t;
	while (t--){
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
	//	vector<pair<int,int> >out(n+1);
	for (int i = 1;  i <= n; i++){
		cin >> c[i];
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
	}
	long long gcd = 0;
	for (int i = 1; i <= 80; i++){
		vector<bool> used(n+1);
		for (int j = 1; j <= n; j++){
			 if (rand()%2){
			 	long long x = 0;
			 	for (int k:adj[j]){
			 		if (!used[k])
			 		x += c[k],
					 used[k] = 1;
				 }
				 gcd = __gcd(x,gcd);
			 }
	}
}
cout << gcd <<'\n';
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
const int MOD = 1e9+9 + 134734675425;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	srand (time(NULL));
//	cout << rand();
//	return 0;
	cin >> t;
	while (t--){
	  // int MOD = rand()%127342174301;
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()*rand()%1214546546733%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] = (d[b]+F[a]);
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]=(mp[d[i]] + c[i]);
	}
	long long gcd = 0;

	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
const int MOD = 1e9+9;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> t;
	while (t--){
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] += F[a];
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]+=c[i];
	}
	long long gcd = 0;
	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
const int MOD = 1e9+9 + 134725634675425;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	srand (time(NULL));
//	cout << rand();
//	return 0;
	cin >> t;
	while (t--){
	  // int MOD = rand()%127342174301;
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()*rand();//%121454636546733%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] = (d[b]+F[a]);
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]=(mp[d[i]] + c[i]);
	}
	long long gcd = 0;

	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
const int MOD = 1e9+9+124732676457;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	srand (time(NULL));
//	cout << rand();
//	return 0;
	cin >> t;
	while (t--){
	  // int MOD = rand()%127342174301;
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] = (d[b]+F[a]);
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]=(mp[d[i]] + c[i]);
	}
	long long gcd = 0;

	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
const int MOD = 1e9+9 + 1347346754;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	srand (time(NULL));
//	cout << rand();
//	return 0;
	cin >> t;
	while (t--){
	  // int MOD = rand()%127342174301;
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] = (d[b]+F[a]);
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]=(mp[d[i]] + c[i]);
	}
	long long gcd = 0;

	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
//const int MOD = 1e9+9 + 1e13;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> t;
	while (t--){
	   int MOD = rand();
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()%120328432710;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] += F[a];
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]+=c[i];
	}
	long long gcd = 0;
	if (mp.empty())
	cout <<'w';
	else
	{
	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
	}
}
}


#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ll long long
using namespace std;
const int MOD = 1e9+9;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> t;
	while (t--){
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] += F[a];
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]+=c[i];
	}
	long long gcd = 0;
	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
const int MOD = 1e9+9;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> t;
	while (t--){
	   int MOD = rand()%127342174301;
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] = (d[b]+F[a])%MOD;
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]=(mp[d[i]] + c[i]);
	}
	long long gcd = 0;

	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
using namespace std;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	srand (time(NULL));
	cin >> t;
	while (t--){
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand();
		if (F[i] == 0)
		    F[i] = rand();
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] = (d[b]+F[a]);
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]=(mp[d[i]] + c[i]);
	}
	long long gcd = 0;
	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
const int MOD = 1e9+9 + 134725634675425;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	srand (time(NULL));
//	cout << rand();
//	return 0;
	cin >> t;
	while (t--){
	  // int MOD = rand()%127342174301;
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()*rand()%121454636546733%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] = (d[b]+F[a]);
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]=(mp[d[i]] + c[i]);
	}
	long long gcd = 0;

	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
}
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
//#define ll long long
using namespace std;
const int MOD = 1e9+9 + 1e13;
int n,m,k,t,a,b,F[1000000];
int P;
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> t;
	while (t--){
		map<long long,int> mp;
		cin >> n >> m;
		vector<int> c(n+1),adj[n+1];
		vector<long long> d(n+1,0);

	for (int i = 1;  i <= n; i++){
		cin >> c[i];
		F[i] = rand()%MOD;
	}
	while (m--){
		cin >> a >> b;
		adj[a].pb(b);
		d[b] += F[a];
	}
	for (int i = 1; i <= n; i++){
		if(d[i])
		mp[d[i]]+=c[i];
	}
	long long gcd = 0;
	for (auto i:mp)
		gcd = __gcd(gcd,1ll*i.S);
	cout << gcd <<'\n';
}
}


#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int M = 5e5 + 5;
int cnt[M];
ll c[M];
vector <vector <int> > g;
int n, m;
ull try1() {
    ull gc = 0;
    for(int i = 0; i < n; i++) {
        ull sm = 0;
        for(int j : g[i]) {
            sm += c[j];
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}
ull try2() {
    vector <int> P(n);
    for(int i = 0; i < n; i++) {
        P[i] = i;
        cnt[i] = 0;
    }
    random_shuffle(all(P));
    ull gc = 0;
    ull sm = 0;
    for(int ip = 0; ip < P.size(); ip++) {
        int u = P[ip];
        for(int v : g[u]) {
            if(cnt[v] == 0) {
                sm += c[v];
            }
            cnt[v]++;
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}
ull try3() {
    for(int i = 0; i < n; i++) {
        cnt[i] = 0;
    }
    ull sm = 0;
    for(int i = 0; i < n; i++) {
        for(int u : g[i]) {
            if(cnt[u] == 0) sm += c[u];
            cnt[u]++;
        }
    }
    ull gc = 0;
    for(int i = 0; i < n; i++) {
        for(int u : g[i]) {
            cnt[u]--;
            if(cnt[u] == 0) {
                sm -= c[u];
            }
        }
        gc = __gcd(gc, sm);
        for(int u : g[i]) {
            if(cnt[u] == 0) {
                sm += c[u];
            }
            cnt[u]++;
        }
    }
    return gc;
}
int main() {fio;
    int T;
    cin >> T;
    while(T--) {
        g.clear();
        cin >> n >> m;
        g.resize(n);
        for(int i = 0; i < n; i++) {
            cnt[i] = 0;
        }
        ull h = 0;
        for(int i = 0; i < n; i++) {
            cin >> c[i];
            h = __gcd(h, (ull)c[i]);
        }
        for(int i = 0; i < m; i++) {
            int u, v;
            cin >> u >> v;
            u--; v--;
            g[u].push_back(v);
        }
        ull gc = try1();
        for(int iter = 0; iter < 10; iter++) {
            gc = __gcd(gc, try2());
            if(gc == h) break;
        }
        gc = __gcd(gc, try3());
        cout << gc << endl;
    }

    return 0;
}


#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int M = 5e5 + 5;
int cnt[M];
ll c[M];
vector <vector <int> > g;
int n, m;
ull try1() {
    ull gc = 0;
    for(int i = 0; i < n; i++) {
        ull sm = 0;
        for(int j : g[i]) {
            sm += c[j];
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}
ull try2() {
    vector <int> P(n);
    for(int i = 0; i < n; i++) {
        P[i] = i;
        cnt[i] = 0;
    }
    random_shuffle(all(P));
    ull gc = 0;
    ull sm = 0;
    for(int ip = 0; ip < P.size(); ip++) {
        int u = P[ip];
        for(int v : g[u]) {
            if(cnt[v] == 0) {
                sm += c[v];
            }
            cnt[v]++;
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}
ull try3() {
    for(int i = 0; i < n; i++) {
        cnt[i] = 0;
    }
    ull sm = 0;
    for(int i = 0; i < n; i++) {
        for(int u : g[i]) {
            if(cnt[u] == 0) sm += c[u];
            cnt[u]++;
        }
    }
    ull gc = 0;
    for(int i = 0; i < n; i++) {
        for(int u : g[i]) {
            cnt[u]--;
            if(cnt[u] == 0) {
                sm -= c[u];
            }
        }
        gc = __gcd(gc, sm);
        for(int u : g[i]) {
            if(cnt[u] == 0) {
                sm += c[u];
            }
            cnt[u]++;
        }
    }
    return gc;
}
ull try4() {
    vector <int> P(n);
    for(int i = 0; i < n; i++) {
        P[i] = i;
        cnt[i] = 0;
    }
    sort(all(P), [&](int i, int j){
        return g[i].size() < g[j].size();
    });
    ull gc = 0;
    ull sm = 0;
    for(int ip = 0; ip < P.size(); ip++) {
        int u = P[ip];
        for(int v : g[u]) {
            if(cnt[v] == 0) {
                sm += c[v];
            }
            cnt[v]++;
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}
ull try5() {
    vector <int> P(n), content(n);
    for(int i = 0; i < n; i++) {
        for(int j : g[i]) {
            content[i] += c[j];
        }
    }
    for(int i = 0; i < n; i++) {
        P[i] = i;
        cnt[i] = 0;
    }
    sort(all(P), [&](int i, int j){
        return content[i] < content[j];
    });
    ull gc = 0;
    ull sm = 0;
    for(int ip = 0; ip < P.size(); ip++) {
        int u = P[ip];
        for(int v : g[u]) {
            if(cnt[v] == 0) {
                sm += c[v];
            }
            cnt[v]++;
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}
ull try6() {
    vector <int> P(n), content(n);
    for(int i = 0; i < n; i++) {
        for(int j : g[i]) {
            content[i] += c[j];
        }
    }
    for(int i = 0; i < n; i++) {
        P[i] = i;
        cnt[i] = 0;
    }
    sort(all(P), [&](int i, int j){
        return content[i] > content[j];
    });
    ull gc = 0;
    ull sm = 0;
    for(int ip = 0; ip < P.size(); ip++) {
        int u = P[ip];
        for(int v : g[u]) {
            if(cnt[v] == 0) {
                sm += c[v];
            }
            cnt[v]++;
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}

int main() {fio;
    int T;
    cin >> T;
    while(T--) {
        g.clear();
        cin >> n >> m;
        g.resize(n);
        for(int i = 0; i < n; i++) {
            cnt[i] = 0;
        }
        ull h = 0;
        for(int i = 0; i < n; i++) {
            cin >> c[i];
            h = __gcd(h, (ull)c[i]);
        }
        for(int i = 0; i < m; i++) {
            int u, v;
            cin >> u >> v;
            u--; v--;
            g[u].push_back(v);
        }
        ull gc = try1();
        gc = __gcd(gc, try3());
        gc = __gcd(gc, try4());
        gc = __gcd(gc, try5());
        gc = __gcd(gc, try6());
        cout << gc << '\n';
    }

    return 0;
}


#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int M = 5e5 + 5;
int cnt[M];
ll c[M];
vector <vector <int> > g;
int n, m;
ull try1() {
    ull gc = 0;
    for(int i = 0; i < n; i++) {
        ull sm = 0;
        for(int j : g[i]) {
            sm += c[j];
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}
ull try2() {
    vector <int> P(n);
    for(int i = 0; i < n; i++) {
        P[i] = i;
        cnt[i] = 0;
    }
    random_shuffle(all(P));
    ull gc = 0;
    ull sm = 0;
    for(int ip = 0; ip < P.size(); ip++) {
        int u = P[ip];
        for(int v : g[u]) {
            if(cnt[v] == 0) {
                sm += c[v];
            }
            cnt[v]++;
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}
ull try3() {
    for(int i = 0; i < n; i++) {
        cnt[i] = 0;
    }
    ull sm = 0;
    for(int i = 0; i < n; i++) {
        for(int u : g[i]) {
            if(cnt[u] == 0) sm += c[u];
            cnt[u]++;
        }
    }
    ull gc = 0;
    for(int i = 0; i < n; i++) {
        for(int u : g[i]) {
            cnt[u]--;
            if(cnt[u] == 0) {
                sm -= c[u];
            }
        }
        gc = __gcd(gc, sm);
        for(int u : g[i]) {
            if(cnt[u] == 0) {
                sm += c[u];
            }
            cnt[u]++;
        }
    }
    return gc;
}
int main() {fio;
    int T;
    cin >> T;
    while(T--) {
        g.clear();
        cin >> n >> m;
        g.resize(n);
        for(int i = 0; i < n; i++) {
            cnt[i] = 0;
        }
        ull h = 0;
        for(int i = 0; i < n; i++) {
            cin >> c[i];
            h = __gcd(h, (ull)c[i]);
        }
        for(int i = 0; i < m; i++) {
            int u, v;
            cin >> u >> v;
            u--; v--;
            g[u].push_back(v);
        }
        ull gc = try1();
        for(int iter = 0; iter < 30; iter++) {
            gc = __gcd(gc, try2());
            if(gc == h) break;
        }
        gc = __gcd(gc, try3());
        cout << gc << endl;
    }

    return 0;
}


#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int M = 5e5 + 5;
int cnt[M];
ll c[M];
vector <vector <int> > g;
int n, m;
ull try1() {
    ull gc = 0;
    for(int i = 0; i < n; i++) {
        ull sm = 0;
        for(int j : g[i]) {
            sm += c[j];
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}
ull try2() {
    vector <int> P(n);
    for(int i = 0; i < n; i++) {
        P[i] = i;
        cnt[i] = 0;
    }
    random_shuffle(all(P));
    ull gc = 0;
    ull sm = 0;
    for(int ip = 0; ip < P.size(); ip++) {
        int u = P[ip];
        for(int v : g[u]) {
            if(cnt[v] == 0) {
                sm += c[v];
            }
            cnt[v]++;
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}
ull try3() {
    for(int i = 0; i < n; i++) {
        cnt[i] = 0;
    }
    ull sm = 0;
    for(int i = 0; i < n; i++) {
        for(int u : g[i]) {
            if(cnt[u] == 0) sm += c[u];
            cnt[u]++;
        }
    }
    ull gc = 0;
    for(int i = 0; i < n; i++) {
        for(int u : g[i]) {
            cnt[u]--;
            if(cnt[u] == 0) {
                sm -= c[u];
            }
        }
        gc = __gcd(gc, sm);
        for(int u : g[i]) {
            if(cnt[u] == 0) {
                sm += c[u];
            }
            cnt[u]++;
        }
    }
    return gc;
}
ull try4() {
    vector <int> P(n);
    for(int i = 0; i < n; i++) {
        P[i] = i;
        cnt[i] = 0;
    }
    sort(all(P), [&](int i, int j){
        return g[i].size() < g[j].size();
    });
    ull gc = 0;
    ull sm = 0;
    for(int ip = 0; ip < P.size(); ip++) {
        int u = P[ip];
        for(int v : g[u]) {
            if(cnt[v] == 0) {
                sm += c[v];
            }
            cnt[v]++;
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}
ull try5() {
    vector <int> P(n), content(n);
    for(int i = 0; i < n; i++) {
        for(int j : g[i]) {
            content[i] += c[j];
        }
    }
    for(int i = 0; i < n; i++) {
        P[i] = i;
        cnt[i] = 0;
    }
    sort(all(P), [&](int i, int j){
        return content[i] < content[j];
    });
    ull gc = 0;
    ull sm = 0;
    for(int ip = 0; ip < P.size(); ip++) {
        int u = P[ip];
        for(int v : g[u]) {
            if(cnt[v] == 0) {
                sm += c[v];
            }
            cnt[v]++;
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}
ull try6() {
    vector <int> P(n), content(n);
    for(int i = 0; i < n; i++) {
        for(int j : g[i]) {
            content[i] += c[j];
        }
    }
    for(int i = 0; i < n; i++) {
        P[i] = i;
        cnt[i] = 0;
    }
    sort(all(P), [&](int i, int j){
        return content[i] > content[j];
    });
    ull gc = 0;
    ull sm = 0;
    for(int ip = 0; ip < P.size(); ip++) {
        int u = P[ip];
        for(int v : g[u]) {
            if(cnt[v] == 0) {
                sm += c[v];
            }
            cnt[v]++;
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}

int main() {fio;
    int T;
    cin >> T;
    while(T--) {
        g.clear();
        cin >> n >> m;
        g.resize(n);
        for(int i = 0; i < n; i++) {
            cnt[i] = 0;
        }
        ull h = 0;
        for(int i = 0; i < n; i++) {
            cin >> c[i];
            h = __gcd(h, (ull)c[i]);
        }
        for(int i = 0; i < m; i++) {
            int u, v;
            cin >> u >> v;
            u--; v--;
            g[u].push_back(v);
        }
        ull gc = try1();
        for(int iter = 0; iter < 10; iter++) {
            gc = __gcd(gc, try2());
            if(gc == h) break;
        }
        gc = __gcd(gc, try3());
        gc = __gcd(gc, try4());
        gc = __gcd(gc, try5());
        gc = __gcd(gc, try6());
        cout << gc << endl;
    }

    return 0;
}


#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int M = 5e5 + 5;
int cnt[M];
ll c[M];
vector <vector <int> > g;
int n, m;
ull try1() {
    ull gc = 0;
    for(int i = 0; i < n; i++) {
        ull sm = 0;
        for(int j : g[i]) {
            sm += c[j];
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}
ull try2() {
    vector <int> P(n);
    for(int i = 0; i < n; i++) {
        P[i] = i;
        cnt[i] = 0;
    }
    random_shuffle(all(P));
    ull gc = 0;
    ull sm = 0;
    for(int ip = 0; ip < P.size(); ip++) {
        int u = P[ip];
        for(int v : g[u]) {
            if(cnt[v] == 0) {
                sm += c[v];
            }
            cnt[v]++;
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}
ull try3() {
    for(int i = 0; i < n; i++) {
        cnt[i] = 0;
    }
    ull sm = 0;
    for(int i = 0; i < n; i++) {
        for(int u : g[i]) {
            if(cnt[u] == 0) sm += c[u];
            cnt[u]++;
        }
    }
    ull gc = 0;
    for(int i = 0; i < n; i++) {
        for(int u : g[i]) {
            cnt[u]--;
            if(cnt[u] == 0) {
                sm -= c[u];
            }
        }
        gc = __gcd(gc, sm);
        for(int u : g[i]) {
            if(cnt[u] == 0) {
                sm += c[u];
            }
            cnt[u]++;
        }
    }
    return gc;
}
ull try4() {
    vector <int> P(n);
    for(int i = 0; i < n; i++) {
        P[i] = i;
        cnt[i] = 0;
    }
    sort(all(P), [&](int i, int j){
        return g[i].size() < g[j].size();
    });
    ull gc = 0;
    ull sm = 0;
    for(int ip = 0; ip < P.size(); ip++) {
        int u = P[ip];
        for(int v : g[u]) {
            if(cnt[v] == 0) {
                sm += c[v];
            }
            cnt[v]++;
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}
ull try5() {
    vector <int> P(n), content(n);
    for(int i = 0; i < n; i++) {
        for(int j : g[i]) {
            content[i] += c[j];
        }
    }
    for(int i = 0; i < n; i++) {
        P[i] = i;
        cnt[i] = 0;
    }
    sort(all(P), [&](int i, int j){
        return content[i] < content[j];
    });
    ull gc = 0;
    ull sm = 0;
    for(int ip = 0; ip < P.size(); ip++) {
        int u = P[ip];
        for(int v : g[u]) {
            if(cnt[v] == 0) {
                sm += c[v];
            }
            cnt[v]++;
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}
ull try6() {
    vector <int> P(n), content(n);
    for(int i = 0; i < n; i++) {
        for(int j : g[i]) {
            content[i] += c[j];
        }
    }
    for(int i = 0; i < n; i++) {
        P[i] = i;
        cnt[i] = 0;
    }
    sort(all(P), [&](int i, int j){
        return content[i] > content[j];
    });
    ull gc = 0;
    ull sm = 0;
    for(int ip = 0; ip < P.size(); ip++) {
        int u = P[ip];
        for(int v : g[u]) {
            if(cnt[v] == 0) {
                sm += c[v];
            }
            cnt[v]++;
        }
        gc = __gcd(gc, sm);
    }
    return gc;
}
constexpr int fib(int n)
{
	if(n <= 2) {
		return 1;
	}
    return fib(n - 1) + fib(n - 2);
}

int main() {fio;
    int T = fib(44);
    cin >> T;
    while(T--) {
        g.clear();
        cin >> n >> m;
        g.resize(n);
        for(int i = 0; i < n; i++) {
            cnt[i] = 0;
        }
        ull h = 0;
        for(int i = 0; i < n; i++) {
            cin >> c[i];
            h = __gcd(h, (ull)c[i]);
        }
        for(int i = 0; i < m; i++) {
            int u, v;
            cin >> u >> v;
            u--; v--;
            g[u].push_back(v);
        }
        ull gc = try1();
        gc = __gcd(gc, try3());
        gc = __gcd(gc, try4());
        gc = __gcd(gc, try5());
        gc = __gcd(gc, try6());
        cout << gc << '\n';
    }

    return 0;
}