import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.reflect.Array;

public class E {
    static final int MOD = 1000000007; // 1e9 + 7
    static final boolean AUTO_FLUSH = false; // slow if true
    // int = num(); // long = ll();
    // string = next(); // a string line = line();
    // ---------------------------------- \

    void main() throws Exception {
        int t = num();
        while (t-- > 0) {
            int n = num(), m = num();
            List<Integer>[] graph = new List[n+1];
            for (int i = 1; i <= n; i++)
                graph[i] = new ArrayList<>();
            for (int i = 0; i < m; i++) {
                int a = num(), b = num();
                graph[a].add(b);
                graph[b].add(a);
            }
            Queue<Integer> q = new LinkedList<>();
            q.add(1);
            HashSet<Integer> odd = new HashSet<>(), even = new HashSet<>();
            odd.add(1);
            int level = 2;
            BitSet vis = new BitSet();
            vis.set(1);
            while (!q.isEmpty()) {
                int now = q.poll();
                for (int i : graph[now]) {
                    if (!vis.get(i)) {
                        vis.set(i);
                        q.add(i);
                        if (level%2 == 0) {
                            even.add(i);
                        } else {
                            odd.add(i);
                        }
                    }
                }
                level++;
            }
            Set<Integer> set = odd.size() > even.size() ? even : odd;
            outln(set.size());
            for (int i : set)
                out(i + " ");
            outln();
        }
    }

    // ---------------------------------- \
    //#region
    public static void main(String[] args) throws Exception {
        new Thread(null, () -> {
            try {
                startTime();
                new E().main();
                boolean endsWithEnter = TO_BE_PRINTED.length() == 0 || TO_BE_PRINTED.charAt(TO_BE_PRINTED.length() - 1) == '\n';
                flush();
                if (!endsWithEnter)
                    log('\n');
                logTime();
                logMem();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "Main", 1<<26).start();
    }
    static Random RAND = new Random();
    static int random(int from, int to) {
        return RAND.nextInt(to-from+1)+from;
    }
    static void logTime() {
        log("Time: " + getTime() + "ms");
    }
    static void logMem() {
        log("Memory (End): " + (int) (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 + " KB");
    }
    static long ll() {
        return Long.parseLong(next());
    }
    static int num() {
        return Integer.parseInt(next());
    }
    static void generateInputMode() throws Exception {
        System.setOut(new PrintStream(new FileOutputStream("F://PROGRAMMING/input.txt")));
    }
    static String line() {
        if (!tokenize())
            return null;
        INPUT_STREAM.setLength(0);
        if (STRING_TOKENIZER.hasMoreTokens())
            INPUT_STREAM.append(STRING_TOKENIZER.nextToken());
        while (STRING_TOKENIZER.hasMoreTokens())
            INPUT_STREAM.append(' ').append(STRING_TOKENIZER.nextToken());
        return INPUT_STREAM.length() == 0 ? null : INPUT_STREAM.toString();
    }
    static void startTime() {
        TIME_COMPLEXITY = System.currentTimeMillis();
    }
    static long getTime() {
        return System.currentTimeMillis() - TIME_COMPLEXITY;
    }
    static void flush() {
        System.out.print(TO_BE_PRINTED.toString());
        TO_BE_PRINTED.setLength(0);
    }
    static void out(Object o) {
        TO_BE_PRINTED.append(o.toString());
        if (AUTO_FLUSH)
            flush();
    }
    static void _log(String s) {
        System.err.print(s);
    }
    static void _logln(String s) {
        System.err.println(s);
    }
    static void _logln() {
        System.err.println();
    }
    static void outln(Object o) {
        out(o);
        outln();
    }
    static void outln() {
        out("\n");
    }
    static class Pair implements Comparable<Pair> {
        public int a, b;
        public Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }
        public static Pair of(int a, int b) {
            return new Pair(a, b);
        }
        public int compareTo(Pair p) {
            if (a == p.a)
                return Integer.compare(b, p.b);
            return Integer.compare(a, p.a);
        }
        public String toString() {
            return "[" + a + "," + b + "]";
        }
        public boolean equals(Pair p) {
            return p.a == a && p.b == b;
        }
    }
    static void logArr(Object val) {
        Class<?> valKlass = val.getClass();
        Object[] outputArray = null;
        for(Class<?> arrKlass : new Class<?>[] { int[].class, float[].class, double[].class, boolean[].class,
            byte[].class, short[].class, long[].class, char[].class }) {
            if (valKlass.isAssignableFrom(arrKlass)) {
                int arrlength = Array.getLength(val);
                outputArray = new Object[arrlength];
                for(int i = 0; i < arrlength; ++i)
                    outputArray[i] = Array.get(val, i);
                break;
            }
        }
        if(outputArray == null)
            outputArray = (Object[])val;
        logArr0(outputArray);
    }
    static void logArr0(Object[] objs) {
        _log("* " + objs[0]);
        for (int i = 1; i < objs.length; i++)
            _log(objs[i].toString().equals("\n") ? "\n>" : (" " + objs[i]));
        _logln();
    }
    static void log(Object... objs) {
        logArr0(objs);
    }
    static String next() {
        return tokenize() ? STRING_TOKENIZER.nextToken() : null;
    }
    static boolean tokenize() {
        if (STRING_TOKENIZER == null || !STRING_TOKENIZER.hasMoreTokens()) {
            try {
                STRING_TOKENIZER = new StringTokenizer(STREAM_READER.readLine());
            } catch (Exception e) {
                return false;
            }
        }
        return true;
    }
    static long TIME_COMPLEXITY;
    static BufferedReader STREAM_READER = new BufferedReader(new InputStreamReader(System.in), 32768);
    static StringTokenizer STRING_TOKENIZER;
    static StringBuilder INPUT_STREAM = new StringBuilder(), TO_BE_PRINTED = new StringBuilder();
    //#endregion
}


import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.reflect.Array;

public class E {
    static final int MOD = 1000000007; // 1e9 + 7
    static final boolean AUTO_FLUSH = false; // slow if true
    // int = num(); // long = ll();
    // string = next(); // a string line = line();
    // ---------------------------------- \

    void main() throws Exception {
        int t = num();
        while (t-- > 0) {
            int n = num(), m = num();
            List<Integer>[] graph = new List[n+1];
            for (int i = 1; i <= n; i++)
                graph[i] = new ArrayList<>();
            for (int i = 0; i < m; i++) {
                int a = num(), b = num();
                graph[a].add(b);
                graph[b].add(a);
            }
            Queue<Integer> q = new LinkedList<>();
            q.add(1);
            HashSet<Integer> odd = new HashSet<>(), even = new HashSet<>();
            odd.add(1);
            int level = 2;
            BitSet vis = new BitSet();
            vis.set(1);
            while (!q.isEmpty()) {
                int now = q.poll();
                for (int i : graph[now]) {
                    if (!vis.get(i)) {
                        vis.set(i);
                        q.add(i);
                        if (level%2 == 0) {
                            even.add(i);
                        } else {
                            odd.add(i);
                        }
                        level++;
                    }
                }
            }
            Set<Integer> set = odd.size() > even.size() ? even : odd;
            outln(set.size());
            for (int i : set)
                out(i + " ");
            outln();
        }
    }

    // ---------------------------------- \
    //#region
    public static void main(String[] args) throws Exception {
        new Thread(null, () -> {
            try {
                startTime();
                new E().main();
                boolean endsWithEnter = TO_BE_PRINTED.length() == 0 || TO_BE_PRINTED.charAt(TO_BE_PRINTED.length() - 1) == '\n';
                flush();
                if (!endsWithEnter)
                    log('\n');
                logTime();
                logMem();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "Main", 1<<26).start();
    }
    static Random RAND = new Random();
    static int random(int from, int to) {
        return RAND.nextInt(to-from+1)+from;
    }
    static void logTime() {
        log("Time: " + getTime() + "ms");
    }
    static void logMem() {
        log("Memory (End): " + (int) (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 + " KB");
    }
    static long ll() {
        return Long.parseLong(next());
    }
    static int num() {
        return Integer.parseInt(next());
    }
    static void generateInputMode() throws Exception {
        System.setOut(new PrintStream(new FileOutputStream("F://PROGRAMMING/input.txt")));
    }
    static String line() {
        if (!tokenize())
            return null;
        INPUT_STREAM.setLength(0);
        if (STRING_TOKENIZER.hasMoreTokens())
            INPUT_STREAM.append(STRING_TOKENIZER.nextToken());
        while (STRING_TOKENIZER.hasMoreTokens())
            INPUT_STREAM.append(' ').append(STRING_TOKENIZER.nextToken());
        return INPUT_STREAM.length() == 0 ? null : INPUT_STREAM.toString();
    }
    static void startTime() {
        TIME_COMPLEXITY = System.currentTimeMillis();
    }
    static long getTime() {
        return System.currentTimeMillis() - TIME_COMPLEXITY;
    }
    static void flush() {
        System.out.print(TO_BE_PRINTED.toString());
        TO_BE_PRINTED.setLength(0);
    }
    static void out(Object o) {
        TO_BE_PRINTED.append(o.toString());
        if (AUTO_FLUSH)
            flush();
    }
    static void _log(String s) {
        System.err.print(s);
    }
    static void _logln(String s) {
        System.err.println(s);
    }
    static void _logln() {
        System.err.println();
    }
    static void outln(Object o) {
        out(o);
        outln();
    }
    static void outln() {
        out("\n");
    }
    static class Pair implements Comparable<Pair> {
        public int a, b;
        public Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }
        public static Pair of(int a, int b) {
            return new Pair(a, b);
        }
        public int compareTo(Pair p) {
            if (a == p.a)
                return Integer.compare(b, p.b);
            return Integer.compare(a, p.a);
        }
        public String toString() {
            return "[" + a + "," + b + "]";
        }
        public boolean equals(Pair p) {
            return p.a == a && p.b == b;
        }
    }
    static void logArr(Object val) {
        Class<?> valKlass = val.getClass();
        Object[] outputArray = null;
        for(Class<?> arrKlass : new Class<?>[] { int[].class, float[].class, double[].class, boolean[].class,
            byte[].class, short[].class, long[].class, char[].class }) {
            if (valKlass.isAssignableFrom(arrKlass)) {
                int arrlength = Array.getLength(val);
                outputArray = new Object[arrlength];
                for(int i = 0; i < arrlength; ++i)
                    outputArray[i] = Array.get(val, i);
                break;
            }
        }
        if(outputArray == null)
            outputArray = (Object[])val;
        logArr0(outputArray);
    }
    static void logArr0(Object[] objs) {
        _log("* " + objs[0]);
        for (int i = 1; i < objs.length; i++)
            _log(objs[i].toString().equals("\n") ? "\n>" : (" " + objs[i]));
        _logln();
    }
    static void log(Object... objs) {
        logArr0(objs);
    }
    static String next() {
        return tokenize() ? STRING_TOKENIZER.nextToken() : null;
    }
    static boolean tokenize() {
        if (STRING_TOKENIZER == null || !STRING_TOKENIZER.hasMoreTokens()) {
            try {
                STRING_TOKENIZER = new StringTokenizer(STREAM_READER.readLine());
            } catch (Exception e) {
                return false;
            }
        }
        return true;
    }
    static long TIME_COMPLEXITY;
    static BufferedReader STREAM_READER = new BufferedReader(new InputStreamReader(System.in), 32768);
    static StringTokenizer STRING_TOKENIZER;
    static StringBuilder INPUT_STREAM = new StringBuilder(), TO_BE_PRINTED = new StringBuilder();
    //#endregion
}


import java.io.ByteArrayInputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class E {

  static boolean LOCAL = System.getProperty("ONLINE_JUDGE") == null;
  public static void main(String[] args) throws Exception {
    new E().go();
  }

  Scanner in;
  String INPUT = "2\n" +
      "4 6\n" +
      "1 2\n" +
      "1 3\n" +
      "1 4\n" +
      "2 3\n" +
      "2 4\n" +
      "3 4\n" +
      "6 8\n" +
      "2 5\n" +
      "5 4\n" +
      "4 3\n" +
      "4 1\n" +
      "1 3\n" +
      "2 3\n" +
      "2 6\n" +
      "5 6";

  void go() {
    if (LOCAL) {
      System.setIn(new ByteArrayInputStream(INPUT.getBytes()));
    }
    in = new Scanner(System.in);
    long startTime = System.currentTimeMillis();
    solve();
    if (LOCAL) {
      System.out.printf("[%dms]", System.currentTimeMillis()-startTime);
    }
    in.close();
  }

  PrintWriter out = new PrintWriter(System.out);
  StringBuffer sb = new StringBuffer();

  class Edge {
    int n1;
    int n2;
    public Edge(int n1, int n2) {
      this.n1 = n1;
      this.n2 = n2;
    }
    @Override
    public String toString() {
      return String.format("%d %d", n1, n2);
    }
  }

  void solve() {

    int t = in.nextInt();

    for (int i = 0; i < t; i++) {
      int n = in.nextInt();
      int m = in.nextInt();
      List<Edge> edges = new ArrayList<>();
      for (int j = 0; j < m; j++) {
        edges.add(new Edge(in.nextInt(), in.nextInt()));
      }
      solve2(n, edges);
    }

  } // end of solve

  void solve2(int n, List<Edge> edges) {

    List<List<Integer>> adj = new ArrayList<>();
    adj.add(new ArrayList<Integer>());
    for (int i = 0; i < n; i++) {
      adj.add(new ArrayList<Integer>());
    }
    for (Edge edge : edges) {
      adj.get(edge.n1).add(edge.n2);
      adj.get(edge.n2).add(edge.n1);
    }

    boolean[] visited = new boolean[n+1];
    boolean isChoosen = true;
    List<Integer> choosen = new ArrayList<>();

    List<Integer> nodeList = new ArrayList<>();
    nodeList.add(1);
    visited[1] = true;

    while (nodeList.size() > 0) {

      List<Integer> nextNodes = new ArrayList<>();
      for (Integer nextN : nodeList) {
        if (isChoosen) {
          choosen.add(nextN);
        }

        for (Integer nextAdj : adj.get(nextN)) {
          if (!visited[nextAdj]) {
            visited[nextAdj] = true;
            nextNodes.add(nextAdj);
          }
        }

      }

      nodeList = nextNodes;
      isChoosen = !isChoosen;
    }

    System.out.println(choosen.size());
    for (Integer c : choosen) {
      System.out.printf("%d ", c);
    }
    System.out.println();
  }

}


import java.io.ByteArrayInputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class E {

  static boolean LOCAL = System.getProperty("ONLINE_JUDGE") == null;
  public static void main(String[] args) throws Exception {
    new E().go();
  }

  Scanner in;
  String INPUT = "2\n" +
      "4 6\n" +
      "1 2\n" +
      "1 3\n" +
      "1 4\n" +
      "2 3\n" +
      "2 4\n" +
      "3 4\n" +
      "6 8\n" +
      "2 5\n" +
      "5 4\n" +
      "4 3\n" +
      "4 1\n" +
      "1 3\n" +
      "2 3\n" +
      "2 6\n" +
      "5 6";

  void go() {
    if (LOCAL) {
      System.setIn(new ByteArrayInputStream(INPUT.getBytes()));
    }
    in = new Scanner(System.in);
    long startTime = System.currentTimeMillis();
    solve();
    if (LOCAL) {
      System.out.printf("[%dms]", System.currentTimeMillis()-startTime);
    }
    in.close();
  }

  PrintWriter out = new PrintWriter(System.out);
  StringBuffer sb = new StringBuffer();

  class Edge {
    int n1;
    int n2;
    public Edge(int n1, int n2) {
      this.n1 = n1;
      this.n2 = n2;
    }
    @Override
    public String toString() {
      return String.format("%d %d", n1, n2);
    }
  }

  void solve() {

    int t = in.nextInt();

    for (int i = 0; i < t; i++) {
      int n = in.nextInt();
      int m = in.nextInt();
      List<Edge> edges = new ArrayList<>();
      for (int j = 0; j < m; j++) {
        edges.add(new Edge(in.nextInt(), in.nextInt()));
      }
      solve2(n, edges);
    }

  } // end of solve

  void solve2(int n, List<Edge> edges) {

    List<List<Integer>> adj = new ArrayList<>();
    adj.add(new ArrayList<Integer>());
    for (int i = 0; i < n; i++) {
      adj.add(new ArrayList<Integer>());
    }
    for (Edge edge : edges) {
      adj.get(edge.n1).add(edge.n2);
      adj.get(edge.n2).add(edge.n1);
    }

    boolean[] visited = new boolean[n+1];
    boolean isChoosen = true;
    List<Integer> choosen = new ArrayList<>();
    List<Integer> unChoosen = new ArrayList<>();

    List<Integer> nodeList = new ArrayList<>();
    nodeList.add(1);
    visited[1] = true;

    while (nodeList.size() > 0) {

      List<Integer> nextNodes = new ArrayList<>();
      for (Integer nextN : nodeList) {
        if (isChoosen) {
          choosen.add(nextN);
        }
        if (!isChoosen) {
          unChoosen.add(nextN);
        }

        for (Integer nextAdj : adj.get(nextN)) {
          if (!visited[nextAdj]) {
            visited[nextAdj] = true;
            nextNodes.add(nextAdj);
          }
        }
      }
      nodeList = nextNodes;
      isChoosen = !isChoosen;
    }

    if (choosen.size() < unChoosen.size()) {
      System.out.println(choosen.size());
      for (Integer c : choosen) {
        System.out.printf("%d ", c);
      }
    } else {
      System.out.println(unChoosen.size());
      for (Integer c : unChoosen) {
        System.out.printf("%d ", c);
      }
    }

    System.out.println();
  }

}


import java.io.ByteArrayInputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class E {

  static boolean LOCAL = System.getProperty("ONLINE_JUDGE") == null;
  public static void main(String[] args) throws Exception {
    new E().go();
  }

  Scanner in;
  String INPUT = "2\n" +
      "4 6\n" +
      "1 2\n" +
      "1 3\n" +
      "1 4\n" +
      "2 3\n" +
      "2 4\n" +
      "3 4\n" +
      "6 8\n" +
      "2 5\n" +
      "5 4\n" +
      "4 3\n" +
      "4 1\n" +
      "1 3\n" +
      "2 3\n" +
      "2 6\n" +
      "5 6";

  void go() {
    if (LOCAL) {
      System.setIn(new ByteArrayInputStream(INPUT.getBytes()));
    }
    in = new Scanner(System.in);
    long startTime = System.currentTimeMillis();
    solve();
    if (LOCAL) {
      System.out.printf("[%dms]", System.currentTimeMillis()-startTime);
    }
    in.close();
  }

  PrintWriter out = new PrintWriter(System.out);
  StringBuffer sb = new StringBuffer();

  class Edge {
    int n1;
    int n2;
    public Edge(int n1, int n2) {
      this.n1 = n1;
      this.n2 = n2;
    }
    @Override
    public String toString() {
      return String.format("%d %d", n1, n2);
    }
  }

  void solve() {

    StringBuffer answer = new StringBuffer();

    int t = in.nextInt();

    for (int i = 0; i < t; i++) {
      int n = in.nextInt();
      int m = in.nextInt();
      List<Edge> edges = new ArrayList<>();
      for (int j = 0; j < m; j++) {
        edges.add(new Edge(in.nextInt(), in.nextInt()));
      }
      solve2(n, edges, answer);
    }

    System.out.println(answer);

  } // end of solve

  void solve2(int n, List<Edge> edges, StringBuffer answer) {

    List<List<Integer>> adj = new ArrayList<>();
    adj.add(new ArrayList<Integer>());
    for (int i = 0; i < n; i++) {
      adj.add(new ArrayList<Integer>());
    }
    for (Edge edge : edges) {
      adj.get(edge.n1).add(edge.n2);
      adj.get(edge.n2).add(edge.n1);
    }

    boolean[] visited = new boolean[n+1];
    boolean isChoosen = true;
    List<Integer> choosen = new ArrayList<>();
    List<Integer> unChoosen = new ArrayList<>();

    List<Integer> nodeList = new ArrayList<>();
    nodeList.add(1);
    visited[1] = true;

    while (nodeList.size() > 0) {

      List<Integer> nextNodes = new ArrayList<>();
      for (Integer nextN : nodeList) {
        if (isChoosen) {
          choosen.add(nextN);
        }
        if (!isChoosen) {
          unChoosen.add(nextN);
        }

        for (Integer nextAdj : adj.get(nextN)) {
          if (!visited[nextAdj]) {
            visited[nextAdj] = true;
            nextNodes.add(nextAdj);
          }
        }
      }
      nodeList = nextNodes;
      isChoosen = !isChoosen;
    }

    if (choosen.size() < unChoosen.size()) {
      //      System.out.println(choosen.size());
      answer.append(choosen.size()+"\n");
      for (Integer c : choosen) {
        // System.out.printf("%d ", c);
        answer.append(c+" ");
      }
    } else {
      //      System.out.println(unChoosen.size());
      answer.append(unChoosen.size()+"\n");
      for (Integer c : unChoosen) {
        // System.out.printf("%d ", c);
        answer.append(c+" ");
      }
    }

    answer.append("\n");
  }

}


import java.io.ByteArrayInputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class E {

  static boolean LOCAL = System.getProperty("ONLINE_JUDGE") == null;
  public static void main(String[] args) throws Exception {
    new E().go();
  }

  Scanner in;
  String INPUT = "2\n" +
      "4 6\n" +
      "1 2\n" +
      "1 3\n" +
      "1 4\n" +
      "2 3\n" +
      "2 4\n" +
      "3 4\n" +
      "6 8\n" +
      "2 5\n" +
      "5 4\n" +
      "4 3\n" +
      "4 1\n" +
      "1 3\n" +
      "2 3\n" +
      "2 6\n" +
      "5 6";

  void go() {
    if (LOCAL) {
      System.setIn(new ByteArrayInputStream(INPUT.getBytes()));
    }
    in = new Scanner(System.in);
    long startTime = System.currentTimeMillis();
    solve();
    if (LOCAL) {
      System.out.printf("[%dms]", System.currentTimeMillis()-startTime);
    }
    in.close();
  }

  PrintWriter out = new PrintWriter(System.out);
  StringBuffer sb = new StringBuffer();

  class Edge {
    int n1;
    int n2;
    public Edge(int n1, int n2) {
      this.n1 = n1;
      this.n2 = n2;
    }
    @Override
    public String toString() {
      return String.format("%d %d", n1, n2);
    }
  }

  void solve() {

    int t = in.nextInt();

    for (int i = 0; i < t; i++) {
      int n = in.nextInt();
      int m = in.nextInt();
      List<Edge> edges = new ArrayList<>();
      for (int j = 0; j < m; j++) {
        edges.add(new Edge(in.nextInt(), in.nextInt()));
      }
      solve2(n, edges);
    }

  } // end of solve

  void solve2(int n, List<Edge> edges) {

    List<List<Integer>> adj = new ArrayList<>();
    adj.add(new ArrayList<Integer>());
    for (int i = 0; i < n; i++) {
      adj.add(new ArrayList<Integer>());
    }
    for (Edge edge : edges) {
      adj.get(edge.n1).add(edge.n2);
      adj.get(edge.n2).add(edge.n1);
    }

    boolean[] visited = new boolean[n+1];
    boolean isChoosen = true;
    List<Integer> choosen = new ArrayList<>();
    List<Integer> unChoosen = new ArrayList<>();

    List<Integer> nodeList = new ArrayList<>();
    nodeList.add(1);
    visited[1] = true;

    while (nodeList.size() > 0) {

      List<Integer> nextNodes = new ArrayList<>();
      for (Integer nextN : nodeList) {
        if (isChoosen) {
          choosen.add(nextN);
        }
        if (!isChoosen) {
          unChoosen.add(nextN);
        }

        for (Integer nextAdj : adj.get(nextN)) {
          if (!visited[nextAdj]) {
            visited[nextAdj] = true;
            nextNodes.add(nextAdj);
          }
        }
      }
      nodeList = nextNodes;
      isChoosen = !isChoosen;
    }

    StringBuffer answer = new StringBuffer();

    if (choosen.size() < unChoosen.size()) {
      System.out.println(choosen.size());
      for (Integer c : choosen) {
        // System.out.printf("%d ", c);
        answer.append(c+" ");
      }
    } else {
      System.out.println(unChoosen.size());
      for (Integer c : unChoosen) {
        // System.out.printf("%d ", c);
        answer.append(c+" ");
      }
    }

    System.out.println(answer);
  }

}


    import java.util.*;
    import java.lang.*;
    import java.io.*;
    public class A{

        public static void main(String[] args){
            InputStream inputStream = System.in;
            InputReader in = new InputReader(inputStream);
            OutputStream outputStream = System.out;
            PrintWriter out = new PrintWriter(outputStream);
            Solver s = new Solver();
            s.solve(in,out);
            out.close();
        }
        static class Solver{

            private class Node{
                LinkedList<Integer> adj;
                int vertex;
                Node(int vertex){
                    this.vertex = vertex;
                    this.adj = new LinkedList<Integer>();
                }
                private void add(int n){
                    this.adj.add(n);
                }

            }

            private void solve(InputReader in, PrintWriter out){
                int t = in.nextInt();
                while(t-->0){
                    int n = in.nextInt();
                    int m = in.nextInt();
                    Solver.Node adj[] = new Solver.Node[n+1];
                    for(int i=0;i<=n;i++)
                        adj[i] = new Solver.Node(i);
                    for(int i=0;i<m;i++){
                        int u = in.nextInt();
                        int v = in.nextInt();
                        adj[u].add(v);
                        adj[v].add(u);
                    }
                    Arrays.sort(adj,new Comparator<Solver.Node>(){
                        public int compare(Solver.Node a, Solver.Node b){
                            return b.adj.size()-a.adj.size();
                        }
                    });
                    HashSet<Integer> chosen = new HashSet<Integer>();
                    int k = 0;
                    for(int u=0;u<n;u++){
                        if(adj[u].adj.size()>=2){
                            int unchosen = 0;
                            for(int el : adj[u].adj){
                                if(!chosen.contains(el)){
                                    unchosen++;
                                }
                            }
                            if(unchosen>=2){
                                chosen.add(adj[u].vertex);
                                k++;
                            }
                            if(k==n/2)
                                break;
                        }
                    }
                    if(k>0){
                        out.println(k);
                        for(int el : chosen){
                            out.print(el+" ");
                        }
                    }
                    else{
                        out.println(1);
                        out.println(1);
                    }
                    out.println();
                }
            }
        }
        static class InputReader {
            public BufferedReader reader;
            public StringTokenizer tokenizer;

            public InputReader(InputStream stream) {
                reader = new BufferedReader(new InputStreamReader(stream), 32768);
                tokenizer = null;
            }

            public String next() {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    try {
                        tokenizer = new StringTokenizer(reader.readLine());
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
                return tokenizer.nextToken();
            }

            public long nextLong() {
                return Long.parseLong(next());
            }
            public int nextInt() {
                return Integer.parseInt(next());
            }
        }
    }


    import java.util.*;
    import java.lang.*;
    import java.io.*;
    public class A{

        public static void main(String[] args){
            InputStream inputStream = System.in;
            InputReader in = new InputReader(inputStream);
            OutputStream outputStream = System.out;
            PrintWriter out = new PrintWriter(outputStream);
            Solver s = new Solver();
            s.solve(in,out);
            out.close();
        }
        static class Solver{

            private void dfs(LinkedList<Integer> adj[],int color[],int v){
                for(int el : adj[v]){
                    if(el!=v && color[el]==0){
                        color[el] = color[v]==1?2:1;
                        dfs(adj,color,el);
                    }
                }
            }
            private void solve(InputReader in, PrintWriter out){
                int t = in.nextInt();
                while(t-->0){
                    int n = in.nextInt();
                    int m = in.nextInt();
                    LinkedList adj[] = new LinkedList[n+1];
                    for(int i=0;i<=n;i++)
                        adj[i] = new LinkedList<Integer>();
                    for(int i=0;i<m;i++){
                        int u = in.nextInt();
                        int v = in.nextInt();
                        adj[u].add(v);
                        adj[v].add(u);
                    }
                    HashSet<Integer> chosen = new HashSet<Integer>();
                    // int k = 0;
                    int color[] = new int[n+1];
                    for(int u=1;u<=n;u++){
                        if(color[u]==0){
                            color[u] = 1;
                            dfs(adj,color,u);
                        }
                    }

                    for(int i=1;i<=n;i++){
                        if(color[i]==1)
                            chosen.add(i);
                    }
                    int k = chosen.size();
                    if(k>=n-k){
                        out.println(n-k);
                        for(int i=1;i<=n;i++){
                            if(!chosen.contains(i))
                                out.print(i+" ");
                        }
                    }
                    else{
                        out.println(k);
                        for(int i=1;i<=n;i++){
                            if(chosen.contains(i))
                                out.print(i+" ");
                        }
                    }
                    out.println();
                }
            }
        }
        static class InputReader {
            public BufferedReader reader;
            public StringTokenizer tokenizer;

            public InputReader(InputStream stream) {
                reader = new BufferedReader(new InputStreamReader(stream), 32768);
                tokenizer = null;
            }

            public String next() {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    try {
                        tokenizer = new StringTokenizer(reader.readLine());
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
                return tokenizer.nextToken();
            }

            public long nextLong() {
                return Long.parseLong(next());
            }
            public int nextInt() {
                return Integer.parseInt(next());
            }
        }
    }


    import java.util.*;
    import java.lang.*;
    import java.io.*;
    public class A{

        public static void main(String[] args){
            InputStream inputStream = System.in;
            InputReader in = new InputReader(inputStream);
            OutputStream outputStream = System.out;
            PrintWriter out = new PrintWriter(outputStream);
            Solver s = new Solver();
            s.solve(in,out);
            out.close();
        }
        static class Solver{

            private class Node{
                LinkedList<Integer> adj;
                int vertex;
                Node(int vertex){
                    this.vertex = vertex;
                    this.adj = new LinkedList<Integer>();
                }
                private void add(int n){
                    this.adj.add(n);
                }

            }

            private void solve(InputReader in, PrintWriter out){
                int t = in.nextInt();
                while(t-->0){
                    int n = in.nextInt();
                    int m = in.nextInt();
                    Solver.Node adj[] = new Solver.Node[n+1];
                    for(int i=0;i<=n;i++)
                        adj[i] = new Solver.Node(i);
                    for(int i=0;i<m;i++){
                        int u = in.nextInt();
                        int v = in.nextInt();
                        adj[u].add(v);
                        adj[v].add(u);
                    }
                    Arrays.sort(adj,new Comparator<Solver.Node>(){
                        public int compare(Solver.Node a, Solver.Node b){
                            return b.adj.size()-a.adj.size();
                        }
                    });
                    HashSet<Integer> chosen = new HashSet<Integer>();
                    int k = 0;
                    for(int u=0;u<n;u++){
                        if(adj[u].adj.size()>=2){
                            int unchosen = 0;
                            for(int el : adj[u].adj){
                                if(!chosen.contains(el)){
                                    unchosen++;
                                }
                            }
                            if(unchosen>=2){
                                chosen.add(adj[u].vertex);
                                k++;
                            }
                            if(k==n/2)
                                break;
                        }
                    }
                    out.println(k);
                    for(int el : chosen){
                        out.print(el+" ");
                    }
                    out.println();
                }
            }
        }
        static class InputReader {
            public BufferedReader reader;
            public StringTokenizer tokenizer;

            public InputReader(InputStream stream) {
                reader = new BufferedReader(new InputStreamReader(stream), 32768);
                tokenizer = null;
            }

            public String next() {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    try {
                        tokenizer = new StringTokenizer(reader.readLine());
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
                return tokenizer.nextToken();
            }

            public long nextLong() {
                return Long.parseLong(next());
            }
            public int nextInt() {
                return Integer.parseInt(next());
            }
        }
    }


    import java.util.*;
    import java.lang.*;
    import java.io.*;
    public class A{

        public static void main(String[] args){
            InputStream inputStream = System.in;
            InputReader in = new InputReader(inputStream);
            OutputStream outputStream = System.out;
            PrintWriter out = new PrintWriter(outputStream);
            Solver s = new Solver();
            s.solve(in,out);
            out.close();
        }
        static class Solver{

            // static int check=0;
            private int f(int x,Stack<Integer> a){
                while(!a.isEmpty() && x>a.peek()){
                    a.pop();
                }
                if(a.isEmpty())
                    return -1;
                return a.pop();
                // int l=0,r = a.size()-1;
                // // if(check==0)
                // //     System.out.println(a);
                // // check++;
                // if(r==-1)
                //     return -1;
                // if(r==0){
                //     if(a.get(0)>x)
                //         return 0;
                //     return -1;
                // }
                // if(r==1){
                //     if(a.get(0)>x)
                //         return 0;
                //     else if(a.get(1)>x)
                //         return 1;
                //     return -1;
                // }
                // if(a.get(r)<x)
                //     return -1;
                // while(r-l>1){
                //     int mid = l+(r-l)/2;  // l + (r-l)/2 is much safer. Use long here if needed
                //     if(a.get(mid)>x){
                //         r = mid;  //r index satisfies
                //     }
                //     else{
                //         l = mid+1; // l index does not satisfy
                //     }
                // }
                // if(r >0 && a.get(r-1)>x)
                //     return a.get(r-1);
                // return a.get(r) ;
            }

            private void solve(InputReader in, PrintWriter out){
                int t = in.nextInt();
                while(t-->0){
                    int n = in.nextInt();
                    int m = in.nextInt();
                    LinkedList<Integer> adj[] = new LinkedList[n+1];
                    for(int i=1;i<=n;i++)
                        adj[i] = new LinkedList<Integer>();
                    for(int i=0;i<m;i++){
                        int u = in.nextInt();
                        int v = in.nextInt();
                        adj[u].add(v);
                        adj[v].add(u);
                    }
                    HashSet<Integer> chosen = new HashSet<Integer>();
                    for(int u=1;u<=n;u++){
                        if(adj[u].size()>=2){
                            int unchosen = 0;
                            for(int el : adj[u]){
                                if(!chosen.contains(el)){
                                    unchosen++;
                                }
                            }
                            if(unchosen>=2)
                                chosen.add(u);
                        }
                    }
                    out.println(chosen.size());
                    for(int el : chosen){
                        out.print(el+" ");
                    }
                    out.println();
                }
            }
        }
        static class InputReader {
            public BufferedReader reader;
            public StringTokenizer tokenizer;

            public InputReader(InputStream stream) {
                reader = new BufferedReader(new InputStreamReader(stream), 32768);
                tokenizer = null;
            }

            public String next() {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    try {
                        tokenizer = new StringTokenizer(reader.readLine());
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
                return tokenizer.nextToken();
            }

            public long nextLong() {
                return Long.parseLong(next());
            }
            public int nextInt() {
                return Integer.parseInt(next());
            }
        }
    }


    import java.util.*;
    import java.lang.*;
    import java.io.*;
    public class A{

        public static void main(String[] args){
            InputStream inputStream = System.in;
            InputReader in = new InputReader(inputStream);
            OutputStream outputStream = System.out;
            PrintWriter out = new PrintWriter(outputStream);
            Solver s = new Solver();
            s.solve(in,out);
            out.close();
        }
        static class Solver{

            private class Node{
                LinkedList<Integer> adj;
                int vertex;
                Node(int vertex){
                    this.vertex = vertex;
                    this.adj = new LinkedList<Integer>();
                }
                private void add(int n){
                    this.adj.add(n);
                }

            }

            private void solve(InputReader in, PrintWriter out){
                int t = in.nextInt();
                while(t-->0){
                    int n = in.nextInt();
                    int m = in.nextInt();
                    Solver.Node adj[] = new Solver.Node[n+1];
                    for(int i=0;i<=n;i++)
                        adj[i] = new Solver.Node(i);
                    for(int i=0;i<m;i++){
                        int u = in.nextInt();
                        int v = in.nextInt();
                        adj[u].add(v);
                        adj[v].add(u);
                    }
                    Arrays.sort(adj,new Comparator<Solver.Node>(){
                        public int compare(Solver.Node a, Solver.Node b){
                            return b.adj.size()-a.adj.size();
                        }
                    });
                    HashSet<Integer> chosen = new HashSet<Integer>();
                    int k = 0;
                    for(int u=0;u<n;u++){
                        if(adj[u].adj.size()>=2){
                            int unchosen = 0;
                            for(int el : adj[u].adj){
                                if(!chosen.contains(el)){
                                    unchosen++;
                                }
                            }
                            if(unchosen>=2){
                                chosen.add(adj[u].vertex);
                                k++;
                            }
                            if(k>n/2)
                                break;
                        }
                    }
                    out.println(k);
                    for(int el : chosen){
                        out.print(el+" ");
                    }
                    out.println();
                }
            }
        }
        static class InputReader {
            public BufferedReader reader;
            public StringTokenizer tokenizer;

            public InputReader(InputStream stream) {
                reader = new BufferedReader(new InputStreamReader(stream), 32768);
                tokenizer = null;
            }

            public String next() {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    try {
                        tokenizer = new StringTokenizer(reader.readLine());
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
                return tokenizer.nextToken();
            }

            public long nextLong() {
                return Long.parseLong(next());
            }
            public int nextInt() {
                return Integer.parseInt(next());
            }
        }
    }


import java.util.*;
import java.io.*;
import java.math.*;
import java.util.regex.*;

public class Main4
{
	public static void main(String[] args)throws Exception
	{
	    Reader reader = new Reader();

		reader.readLine();
		int t = reader.readInt(0);

		StringBuilder res = new StringBuilder();
		while (t-- > 0)
		{
			reader.readLine();
			int n = reader.readInt(0);
			int m = reader.readInt(1);

			List<List<Integer>> graph = new ArrayList<>();
			for (int i=0;i <= n;++i)
			{
				graph.add(new ArrayList<Integer>());
			}

			for (int i=0;i < m;++i)
			{
				reader.readLine();
				graph.get(reader.readInt(0)).add(reader.readInt(1));
				graph.get(reader.readInt(1)).add(reader.readInt(0));
			}

			Queue<Pair> queue = new LinkedList<>();
			queue.add(new Pair(1, 0));

			int shouldBe = n / 2;
			boolean []vis = new boolean[n + 1];
			boolean []inAns = new boolean[n + 1];
			while (!queue.isEmpty())
			{
				Pair p = queue.poll();
				int v = p.index;
				int l = p.level;

				if(vis[v])
					continue;

				vis[v] = true;
				if (l % 2 == 0)
				{
					inAns[v] = true;
					--shouldBe;
				}

				for (int vv:graph.get(v))
				{
					if (!vis[vv])
					{
						queue.add(new Pair(vv, l + 1));
					}
				}
			}

			boolean flag = true;
			if (shouldBe < 0)
			{
				shouldBe += n;
				flag = false;
			}
			else
			{
				shouldBe = n/2 -shouldBe;
			}

			res.append(shouldBe).append("\n");
			for (int i=1;i <= n;++i)
			{
				if (inAns[i] == flag)
					res.append(i).append(" ");
			}

			res.append("\n");
		}

		System.out.print(res.toString());
		reader.close();
	}
}

class Pair
{
	int index;
	int level;

	public Pair(int index, int level)
	{
		this.index = index;
		this.level = level;
	}

	@Override
	public String toString()
	{
		return index +" "+level;
	}

}

class Reader
{
    private BufferedReader reader;
    private String line[];

    public Reader()
    {
        reader = new BufferedReader(new InputStreamReader(System.in));
    }

    public String[] getLine()
    {
        return line;
    }

    public boolean readLine()     throws IOException
    {
        String str = reader.readLine();
        if (str == null || str.isEmpty())
            return false;
        line = line = str.split(" ");
        return true;
    }

    public List<Integer> getIntegersList()
    {
        List<Integer> res = new ArrayList<>();
        for (String str:line)
            res.add(Integer.parseInt(str));
        return res;

    }

	public List<Long> getLongsList()
    {
        List<Long> res = new ArrayList<>();
        for (String str:line)
            res.add(Long.parseLong(str));
        return res;

    }

    public int readInt(int pos)throws IOException
    {
        return Integer.parseInt(line[pos]);
    }

    public double readDouble(int pos)throws IOException
    {
        return Double.parseDouble(line[pos]);
    }

    public long readLong(int pos)throws IOException
    {
        return Long.parseLong(line[pos]);
    }

    public String readString(int pos)throws IOException
    {
        return line[pos];
    }

    public void close()throws IOException
    {
        reader.close();
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.util.regex.*;

public class Main4
{
	public static void main(String[] args)throws Exception
	{
	    Reader reader = new Reader();

		reader.readLine();
		int t = reader.readInt(0);

		StringBuilder res = new StringBuilder();
		while (t-- > 0)
		{
			reader.readLine();
			int n = reader.readInt(0);
			int m = reader.readInt(1);

			List<List<Integer>> graph = new ArrayList<>();
			for (int i=0;i <= n;++i)
			{
				graph.add(new ArrayList<Integer>());
			}

			for (int i=0;i < m;++i)
			{
				reader.readLine();
				graph.get(reader.readInt(0)).add(reader.readInt(1));
				graph.get(reader.readInt(1)).add(reader.readInt(0));
			}

			Queue<Pair> queue = new LinkedList<>();
			queue.add(new Pair(1, 0));

			int shouldBe = n / 2;
			boolean []vis = new boolean[n + 1];
			boolean []inAns = new boolean[n + 1];
			while (!queue.isEmpty())
			{
				Pair p = queue.poll();
				int v = p.index;
				int l = p.level;

				if(vis[v])
					continue;

				vis[v] = true;
				if (l % 2 == 0)
				{
					inAns[v] = true;
					--shouldBe;
				}

				for (int vv:graph.get(v))
				{
					if (!vis[vv])
					{
						queue.add(new Pair(vv, l + 1));
					}
				}
			}

			boolean flag = true;
			if (shouldBe < 0)
				flag = false;

			for (int i=1;i <= n;++i)
			{
				if (inAns[i] == flag)
					res.append(i).append(" ");
			}

			res.append("\n");
		}

		System.out.print(res.toString());
		reader.close();
	}
}

class Pair
{
	int index;
	int level;

	public Pair(int index, int level)
	{
		this.index = index;
		this.level = level;
	}

	@Override
	public String toString()
	{
		return index +" "+level;
	}

}

class Reader
{
    private BufferedReader reader;
    private String line[];

    public Reader()
    {
        reader = new BufferedReader(new InputStreamReader(System.in));
    }

    public String[] getLine()
    {
        return line;
    }

    public boolean readLine()     throws IOException
    {
        String str = reader.readLine();
        if (str == null || str.isEmpty())
            return false;
        line = line = str.split(" ");
        return true;
    }

    public List<Integer> getIntegersList()
    {
        List<Integer> res = new ArrayList<>();
        for (String str:line)
            res.add(Integer.parseInt(str));
        return res;

    }

	public List<Long> getLongsList()
    {
        List<Long> res = new ArrayList<>();
        for (String str:line)
            res.add(Long.parseLong(str));
        return res;

    }

    public int readInt(int pos)throws IOException
    {
        return Integer.parseInt(line[pos]);
    }

    public double readDouble(int pos)throws IOException
    {
        return Double.parseDouble(line[pos]);
    }

    public long readLong(int pos)throws IOException
    {
        return Long.parseLong(line[pos]);
    }

    public String readString(int pos)throws IOException
    {
        return line[pos];
    }

    public void close()throws IOException
    {
        reader.close();
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.util.regex.*;

public class Main4
{
	public static void main(String[] args)throws Exception
	{
	    Reader reader = new Reader();

		reader.readLine();
		int t = reader.readInt(0);

		StringBuilder res = new StringBuilder();
		while (t-- > 0)
		{
			reader.readLine();
			int n = reader.readInt(0);
			int m = reader.readInt(1);

			List<List<Integer>> graph = new ArrayList<>();
			for (int i=0;i <= n;++i)
			{
				graph.add(new ArrayList<Integer>());
			}

			for (int i=0;i < m;++i)
			{
				reader.readLine();
				graph.get(reader.readInt(0)).add(reader.readInt(1));
				graph.get(reader.readInt(1)).add(reader.readInt(0));
			}

			Queue<Pair> queue = new LinkedList<>();
			queue.add(new Pair(1, 0));

			int shouldBe = n / 2;
			boolean []vis = new boolean[n + 1];
			boolean []inAns = new boolean[n + 1];
			while (!queue.isEmpty())
			{
				Pair p = queue.poll();
				int v = p.index;
				int l = p.level;

				if(vis[v])
					continue;

				vis[v] = true;
				if (l % 2 == 0)
				{
					inAns[v] = true;
					--shouldBe;
				}

				for (int vv:graph.get(v))
				{
					if (!vis[vv])
					{
						queue.add(new Pair(vv, l + 1));
					}
				}
			}

			boolean flag = true;
			if (shouldBe < 0)
			{
				shouldBe += n;
				flag = false;
			}

			res.append(shouldBe).append("\n");
			for (int i=1;i <= n;++i)
			{
				if (inAns[i] == flag)
					res.append(i).append(" ");
			}

			res.append("\n");
		}

		System.out.print(res.toString());
		reader.close();
	}
}

class Pair
{
	int index;
	int level;

	public Pair(int index, int level)
	{
		this.index = index;
		this.level = level;
	}

	@Override
	public String toString()
	{
		return index +" "+level;
	}

}

class Reader
{
    private BufferedReader reader;
    private String line[];

    public Reader()
    {
        reader = new BufferedReader(new InputStreamReader(System.in));
    }

    public String[] getLine()
    {
        return line;
    }

    public boolean readLine()     throws IOException
    {
        String str = reader.readLine();
        if (str == null || str.isEmpty())
            return false;
        line = line = str.split(" ");
        return true;
    }

    public List<Integer> getIntegersList()
    {
        List<Integer> res = new ArrayList<>();
        for (String str:line)
            res.add(Integer.parseInt(str));
        return res;

    }

	public List<Long> getLongsList()
    {
        List<Long> res = new ArrayList<>();
        for (String str:line)
            res.add(Long.parseLong(str));
        return res;

    }

    public int readInt(int pos)throws IOException
    {
        return Integer.parseInt(line[pos]);
    }

    public double readDouble(int pos)throws IOException
    {
        return Double.parseDouble(line[pos]);
    }

    public long readLong(int pos)throws IOException
    {
        return Long.parseLong(line[pos]);
    }

    public String readString(int pos)throws IOException
    {
        return line[pos];
    }

    public void close()throws IOException
    {
        reader.close();
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.util.regex.*;

public class Main4
{
	public static void main(String[] args)throws Exception
	{
	    Reader reader = new Reader();

		reader.readLine();
		int t = reader.readInt(0);

		StringBuilder res = new StringBuilder();
		while (t-- > 0)
		{
			reader.readLine();
			int n = reader.readInt(0);
			int m = reader.readInt(1);

			List<List<Integer>> graph = new ArrayList<>();
			for (int i=0;i <= n;++i)
			{
				graph.add(new ArrayList<Integer>());
			}

			for (int i=0;i < m;++i)
			{
				reader.readLine();
				graph.get(reader.readInt(0)).add(reader.readInt(1));
				graph.get(reader.readInt(1)).add(reader.readInt(0));
			}

			Queue<Pair> queue = new LinkedList<>();
			queue.add(new Pair(1, 0));

			int get = 0;
			boolean []vis = new boolean[n + 1];
			boolean []inAns = new boolean[n + 1];
			while (!queue.isEmpty())
			{
				Pair p = queue.poll();
				int v = p.index;
				int l = p.level;

				if(vis[v])
					continue;

				vis[v] = true;
				if (l % 2 == 0)
				{
					inAns[v] = true;
					++get;
				}

				for (int vv:graph.get(v))
				{
					if (!vis[vv])
					{
						queue.add(new Pair(vv, l + 1));
					}
				}
			}

			boolean flag = true;
			if (get > n/2)
			{
				get = n-get;
				flag = false;
			}

			res.append(get).append("\n");
			for (int i=1;i <= n;++i)
			{
				if (inAns[i] == flag)
					res.append(i).append(" ");
			}

			res.append("\n");
		}

		System.out.print(res.toString());
		reader.close();
	}
}

class Pair
{
	int index;
	int level;

	public Pair(int index, int level)
	{
		this.index = index;
		this.level = level;
	}

	@Override
	public String toString()
	{
		return index +" "+level;
	}

}

class Reader
{
    private BufferedReader reader;
    private String line[];

    public Reader()
    {
        reader = new BufferedReader(new InputStreamReader(System.in));
    }

    public String[] getLine()
    {
        return line;
    }

    public boolean readLine()     throws IOException
    {
        String str = reader.readLine();
        if (str == null || str.isEmpty())
            return false;
        line = line = str.split(" ");
        return true;
    }

    public List<Integer> getIntegersList()
    {
        List<Integer> res = new ArrayList<>();
        for (String str:line)
            res.add(Integer.parseInt(str));
        return res;

    }

	public List<Long> getLongsList()
    {
        List<Long> res = new ArrayList<>();
        for (String str:line)
            res.add(Long.parseLong(str));
        return res;

    }

    public int readInt(int pos)throws IOException
    {
        return Integer.parseInt(line[pos]);
    }

    public double readDouble(int pos)throws IOException
    {
        return Double.parseDouble(line[pos]);
    }

    public long readLong(int pos)throws IOException
    {
        return Long.parseLong(line[pos]);
    }

    public String readString(int pos)throws IOException
    {
        return line[pos];
    }

    public void close()throws IOException
    {
        reader.close();
    }
}


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

public class E {

    void solve() {
        int t = in.nextInt();
        for (int tt = 0; tt < t; tt++) {
            int n = in.nextInt();
            int m = in.nextInt();
            List<List<Integer>> adj = new ArrayList<>();
            for (int i = 0; i <= n; i++) {
                adj.add(new ArrayList<>());
            }
            for (int i = 0; i < m; i++) {
                int v = in.nextInt();
                int u = in.nextInt();
                adj.get(v).add(u);
                adj.get(u).add(v);
            }

            HashSet<Integer> painted = new HashSet<>();
            HashSet<Integer> visited = new HashSet<>();

            dfs(1, adj, painted, visited);

            out.println(painted.size());

            for (Integer v : painted) {
                out.print(v + " ");
            }
            out.println();
        }

    }

    private void dfs(int v, List<List<Integer>> adj, HashSet<Integer> painted, HashSet<Integer> visited) {
        if (visited.contains(v)) return;
        visited.add(v);
        boolean connectedToPainted = false;
        for (Integer next : adj.get(v)) {
            if (painted.contains(next)) {
                connectedToPainted = true;
                break;
            }
        }
        if (!connectedToPainted) {
            painted.add(v);
        }
        for (Integer next : adj.get(v)) {
            if (!visited.contains(next)) {
                dfs(next, adj, painted, visited);
            }
        }
    }

    Scanner in;
    PrintWriter out;

    void run() {
        try {
            in = new Scanner(new File("A.in"));
            out = new PrintWriter(new File("A.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new Scanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class Scanner {
        BufferedReader br;
        StringTokenizer st;

        public Scanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public Scanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        private boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        private int skip() {
            int b;
            while ((b = read()) != -1 && isSpaceChar(b)) ;
            return b;
        }

        private int read() {
            int res = -1;
            try {
                res = br.read();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return res;
        }

        char[] nextCharArray(int size) {
            char[] buf = new char[size];
            int b = skip(), p = 0;
            while (p < size && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = read();
            }
            return size == p ? buf : Arrays.copyOf(buf, p);
        }

        char[][] nextCharMap(int n, int m) {
            char[][] map = new char[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextCharArray(m);
            }
            return map;
        }

        int[] na(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }
            return arr;
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

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

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

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

    public static void main(String[] args) {
        new E().runIO();
    }
}


#include<bits/stdc++.h>
using namespace std;
bool comp(pair<int,int> a,pair<int,int> b)
{
	return a.second<b.second;
}
int main()
{
int t;cin>>t;
while(t--)
{
	int a,b,c;cin>>a>>b>>c;
	if(a!=b&&b!=c&&c!=a)
	{
	cout<<"NO"<<endl;
	continue;
	}
	int mini=min(a,min(b,c));
	if(a==mini&&b==mini&&c!=mini||b==mini&&c==mini&&a!=mini||c==mini&&a==mini&&b!=mini)
	{
	cout<<"NO"<<endl;
	cout<<endl;
	continue;
	}
	else
	{
	    cout<<endl;
		cout<<"YES"<<endl;
		cout<<mini<<" "<<max(a,max(b,c))<<" "<<max(a,max(b,c));
	}

}
}


#include<bits/stdc++.h>
using namespace std;
bool comp(pair<int,int> a,pair<int,int> b)
{
	return a.second<b.second;
}
int main()
{
int t;cin>>t;
while(t--)
{
	int a,b,c;cin>>a>>b>>c;
	if(a!=b&&b!=c&&c!=a)
	{
	cout<<"NO"<<endl;
	continue;
	}
	int mini=min(a,min(b,c));
	if(a==mini&&b==mini&&c!=mini||b==mini&&c==mini&&a!=mini||c==mini&&a==mini&&b!=mini)
	{
	cout<<"NO"<<endl;
	continue;
	}
	else
	{
		cout<<"YES"<<endl;
		cout<<mini<<" "<<max(a,max(b,c))<<" "<<max(a,max(b,c))<<endl;
	}

}
}


#include<bits/stdc++.h>
using namespace std;
bool comp(pair<int,int> a,pair<int,int> b)
{
	return a.second<b.second;
}
int main()
{
int t;cin>>t;
while(t--)
{
	int a,b,c;cin>>a>>b>>c;
	if(a==b&&b==c&&c==a){
	cout<<a<<" "<<b<<" "<<c<<endl;continue;}
	if(a!=b&&b!=c&&c!=a)
	{
	cout<<"NO"<<endl;
	continue;
	}
	int mini=min(a,min(b,c));
	if(a==mini&&b==mini&&c!=mini||b==mini&&c==mini&&a!=mini||c==mini&&a==mini&&b!=mini)
	{
	cout<<"NO"<<endl;
	continue;
	}
	else
	{
		cout<<"YES"<<endl;
		int maxn=max(a,max(b,c));
	/*	if(a==c)
		cout<<maxn-mini<<" "<<mini<<" "<<maxn<<endl;*/
		//else
		cout<<mini<<" "<<mini<<" "<<maxn<<endl;
	}

}
}


#include<bits/stdc++.h>
using namespace std;
bool comp(pair<int,int> a,pair<int,int> b)
{
	return a.second<b.second;
}
int main()
{
int t;cin>>t;
while(t--)
{
	int a,b,c;cin>>a>>b>>c;
	if(a==b&&b==c&&c==a){
	cout<<a<<" "<<b<<" "<<c<<endl;continue;}
	if(a!=b&&b!=c&&c!=a)
	{
	cout<<"NO"<<endl;
	continue;
	}
	int mini=min(a,min(b,c));
	if(a==mini&&b==mini&&c!=mini||b==mini&&c==mini&&a!=mini||c==mini&&a==mini&&b!=mini)
	{
	cout<<"NO"<<endl;
	continue;
	}
	else
	{
		cout<<"YES"<<endl;
		int maxn=max(a,max(b,c));
		if(a==c)
		cout<<maxn-mini<<" "<<mini<<" "<<maxn<<endl;
		else
		cout<<mini<<" "<<maxn<<" "<<maxn<<endl;
	}

}
}


#include<bits/stdc++.h>
using namespace std;
bool comp(pair<int,int> a,pair<int,int> b)
{
	return a.second<b.second;
}
int main()
{
int t;cin>>t;
while(t--)
{
	int a,b,c;cin>>a>>b>>c;
	if(a!=b&&b!=c&&c!=a)
	{
	cout<<"NO"<<endl;
	continue;
	}
	int mini=min(a,min(b,c));
	if(a==mini&&b==mini&&c!=mini||b==mini&&c==mini&&a!=mini||c==mini&&a==mini&&b!=mini)
	{
	cout<<"NO"<<endl;
	continue;
	}
	else
	{
		cout<<endl;
		cout<<"YES"<<endl;
		cout<<mini<<" "<<max(a,max(b,c))<<" "<<max(a,max(b,c));
	}

}
}


#include<bits/stdc++.h>
using namespace std;
bool comp(pair<int,int> a,pair<int,int> b)
{
	return a.second<b.second;
}
int main()
{
int t;cin>>t;
while(t--)
{
	int a,b,c;cin>>a>>b>>c;
	if(a!=b&&b!=c&&c!=a)
	{
	cout<<"NO"<<endl;
	continue;
	}
	int mini=min(a,min(b,c));
	if(a==mini&&b==mini&&c!=mini||b==mini&&c==mini&&a!=mini||c==mini&&a==mini&&b!=mini)
	{
	cout<<"NO"<<endl;
	continue;
	}
	else
	{
		cout<<"YES"<<endl;
		cout<<mini<<" "<<max(a,max(b,c))<<" "<<max(a,max(b,c));
	}

}
}


#include<bits/stdc++.h>
using namespace std;
bool comp(pair<int,int> a,pair<int,int> b)
{
	return a.second<b.second;
}
int main()
{
int t;cin>>t;
while(t--)
{
	int a,b,c;cin>>a>>b>>c;
	if(a==b&&b==c&&c==a){
	cout<<a<<" "<<b<<" "<<c<<endl;continue;}
	if(a!=b&&b!=c&&c!=a)
	{
	cout<<"NO"<<endl;
	continue;
	}
	int mini=min(a,min(b,c));
	if(a==mini&&b==mini&&c!=mini||b==mini&&c==mini&&a!=mini||c==mini&&a==mini&&b!=mini)
	{
	cout<<"NO"<<endl;
	continue;
	}
	else
	{
		cout<<"YES"<<endl;
		int maxn=max(a,max(b,c));
		if(a==c)
		cout<<maxn-mini<<" "<<mini<<" "<<maxn<<endl;
		else
		cout<<mini<<" "<<mini<<" "<<maxn<<endl;
	}

}
}


#include<bits/stdc++.h>
using namespace std;
bool comp(pair<int,int> a,pair<int,int> b)
{
	return a.second<b.second;
}
int main()
{
int t;cin>>t;
while(t--)
{
int a[3];
for(int i=0;i<3;i++)
cin>>a[i];
sort(a,a+3);
if(a[1]!=a[2])
cout<<"NO"<<endl;
else
{
	cout<<"YES"<<endl;
	cout<<a[0]<<" "<<a[0]<<" "<<a[2]<<endl;
	}
}
}


#include <iostream>
using namespace std;

int main() {
	cout<<"GfG!";
	return 0;
}


    #include<bits/stdc++.h>

    using namespace std;

    int main()
    {
            int t, a[5];
            cin>>t;

            while(t--)
            {
                    cin>>a[0]>>a[1]>>a[2];

                    sort(a,a+2);

                    if(a[1] == a[2])
                    cout<<"YES"<<endl<<a[2]<<" "<<a[0]<<" "<<1<<endl;

                    else
                    cout<<"NO"<<endl;
            }

            return 0;
    }


#include<bits/stdc++.h>

using namespace std;

int main()
{
        int t, a[5];
        cin>>t;

        while(t--)
        {
                cin>>a[0]>>a[1]>>a[2];

                sort(a,a+2);

                if(a[1] == a[2])
                cout<<"YES"<<endl<<a[2]<<" "<<a[0]<<" "<<a[0]<<endl;

                else
                cout<<"NO";
        }

        return 0;
}


    #include<bits/stdc++.h>
    using namespace std;
    int t,a[5];
    int main(){
    	cin>>t;
    	while(t--){
    		cin>>a[1]>>a[2]>>a[3];
    		sort(a+1,a+4);

    		if(a[2]!=a[3]) cout<<"No"<<endl;
    		else cout<<"Yes\n"<<a[3]<<" "<<a[1]<<" "<<1<<endl;
    	}
    }


        #include<bits/stdc++.h>

        using namespace std;

        int main()
        {
                long int t, a[3];
                cin>>t;

                while(t--)
                {
                        cin>>a[0]>>a[1]>>a[2];

                        sort(a,a+2);

                        if(a[1] == a[2])
                        cout<<"YES"<<endl<<a[2]<<" "<<a[0]<<" "<<a[0]<<endl;

                        else
                        cout<<"NO"<<endl;
                }

                return 0;
        }


        #include<bits/stdc++.h>

        using namespace std;

        int main()
        {
                long int t, a[5];
                cin>>t;

                while(t--)
                {
                        cin>>a[0]>>a[1]>>a[2];

                        sort(a,a+4);

                        if(a[1] == a[2])
                        cout<<"YES"<<endl<<a[2]<<" "<<a[0]<<" "<<a[0]<<endl;

                        else
                        cout<<"NO"<<endl;
                }

                return 0;
        }


    #include<bits/stdc++.h>

    using namespace std;

    int main()
    {
            long long int t, a[5];
            cin>>t;

            while(t--)
            {
                    cin>>a[0]>>a[1]>>a[2];

                    sort(a,a+2);

                    if(a[1] == a[2])
                    cout<<"YES"<<endl<<a[2]<<" "<<a[0]<<" "<<a[0]<<endl;

                    else
                    cout<<"NO"<<endl;
            }

            return 0;
    }


        #include<bits/stdc++.h>

        using namespace std;

        int t, a[3];

        int main()
        {

                cin>>t;

                while(t--)
                {
                        cin>>a[0]>>a[1]>>a[2];

                        sort(a,a+3);

                        if(a[1] == a[2])
                        cout<<"YES"<<endl<<a[2]<<" "<<a[0]<<" "<<a[0]<<endl;

                        else
                        cout<<"NO"<<endl;
                }

                return 0;
        }


    #include<bits/stdc++.h>
    using namespace std;
    int t,a[5];
    int main(){
    	cin>>t;
    	while(t--){
    		cin>>a[1]>>a[2]>>a[3];
    		sort(a+1,a+4);

    		if(a[2]!=a[3]) cout<<"No"<<endl;
    		else cout<<"Yes\n"<<a[3]<<" "<<a[1]<<" "<<a[1]<<endl;
    	}
    }


        #include<bits/stdc++.h>

        using namespace std;

        int main()
        {
                int t, a[3];
                cin>>t;

                while(t--)
                {
                        cin>>a[0]>>a[1]>>a[2];

                        sort(a,a+3);

                        if(a[1] == a[2])
                        cout<<"YES"<<endl<<a[2]<<" "<<a[0]<<" "<<a[0]<<endl;

                        else
                        cout<<"NO"<<endl;
                }

                return 0;
        }


    #include<bits/stdc++.h>

    using namespace std;

    int main()
    {
            int t, a[5];
            cin>>t;

            while(t--)
            {
                    cin>>a[0]>>a[1]>>a[2];

                    sort(a,a+2);

                    if(a[1] == a[2])
                    cout<<"YES"<<endl<<a[2]<<" "<<a[0]<<" "<<a[0]<<endl;

                    else
                    cout<<"NO"<<endl;
            }

            return 0;
    }


#define ll long long
#include<bits/stdc++.h>
using namespace std;
int32_t main() {

	int t;
	cin >> t;
	// tc = 1;
	while(t--) {
        int a, b, c;
        cin >> a >> c >> b;
        if(a != b && a != c && b != c) {
            cout << "NO" << endl;
        }
        else if(a == b && b >= c) {
            cout << "YES" << endl;
            cout << c << " " << a << " " << c << endl;
        }
        else if(b == c && b >= a) {
            cout << "YES" << endl;
            cout << a << " " << a << " " << c << endl;
        }
        else if(a == c && a >= b) {
            cout << "YES" << endl;
            cout << a << " " << b << " " << (b-1) << endl;
        }
        else cout << "NO" << endl;
    }
}


#define ll long long
#include<bits/stdc++.h>
using namespace std;
int32_t main() {

	int t;
	cin >> t;
	// tc = 1;
	while(t--) {
        int a, b, c;
        cin >> a >> c >> b;
        if(a != b && a != c && b != c) {
            cout << "NO" << endl;
        }
        else if(a == b && b >= c) {
            cout << "YES" << endl;
            cout << c << " " << a << " " << c << endl;
        }
        else if(b == c && b >= a) {
            cout << "YES" << endl;
            cout << a << " " << a << " " << c << endl;
        }
        else if(a == c && a >= b) {
            cout << "YES" << endl;
            cout << a << " " << b << " " << b << endl;
        }
        else cout << "NO" << endl;
    }
}


#define ll long long
#include<bits/stdc++.h>
using namespace std;
int main(){
      int t;cin>>t;
      while(t--){
          ll x,y,z;
          cin>>x>>y>>z;

 if(x==y)
        {
            if(z>x)
            {
                cout<<"NO\n";
            }
            else
            {
                cout<<"YES\n"<<x<<" "<<z<<" "<<max(z,1LL)<<endl;
            }
        }
        else if(x==z)
        {
            if(y>x)
            {
                cout<<"NO\n";
            }
            else
            {
                cout<<"YES\n"<<max(y-1,1LL)<<" "<<x<<" "<<y<<endl;
            }
        }
        else if(y==z)
        {
            if(x>y)
            {
                cout<<"NO\n";
            }
            else
            {
                cout<<"YES\n"<<x<<" "<<max(x,1LL)<<" "<<z<<endl;
            }
        }
        else
        {
            cout<<"NO\n";
        }

    }

	return 0;
}


#define ll long long
#include<bits/stdc++.h>
using namespace std;
int32_t main() {

	int t;
	cin >> t;
	// tc = 1;
	while(t--) {
        int a, b, c;
        cin >> a >> c >> b;
        if(a != b && a != c && b != c) {
            cout << "NO" << endl;
        }
        else if(a == b && b >= c) {
            cout << "YES" << endl;
            cout << c << " " << a << " " << c << endl;
        }
        else if(b == c && b >= a) {
            cout << "YES" << endl;
            cout << a << " " << a << " " << c << endl;
        }
        else if(a == c && a >= b) {
            cout << "YES" << endl;
            cout << a << " " << b << " " << b-1 << endl;
        }
        else cout << "NO" << endl;
    }
}


#define ll long long
#include<bits/stdc++.h>
using namespace std;
int32_t main() {

	int t;
	cin >> t;
	// tc = 1;
	while(t--) {
        int a, b, c;
        cin >> a >> c >> b;
        if(a != b && a != c && b != c) {
            cout << "NO" << endl;
        }
        else if(a == b && b >= c) {
            cout << "YES" << endl;
            cout << c << " " << a << " " << c << endl;
        }
        else if(b == c && b >= a) {
            cout << "YES" << endl;
            cout << a << " " << a << " " << c << endl;
        }
        else if(a == c && a >= b) {
            cout << "YES" << endl;
            cout << a << " " << b << " " << max(b-1,1LL) << endl;
        }
        else cout << "NO" << endl;
    }
}


#define ll long long
#include<bits/stdc=+.h>
using namespace std;
int32_t main() {

	int t;
	cin >> t;
	// tc = 1;
	while(t--) {
        int a, b, c;
        cin >> a >> c >> b;
        if(a != b && a != c && b != c) {
            cout << "NO" << endl;
        }
        else if(a == b && b >= c) {
            cout << "YES" << endl;
            cout << c << " " << a << " " << c << endl;
        }
        else if(b == c && b >= a) {
            cout << "YES" << endl;
            cout << a << " " << a << " " << c << endl;
        }
        else if(a == c && a >= b) {
            cout << "YES" << endl;
            cout << a << " " << b << " " << (b-1) << endl;
        }
        else cout << "NO" << endl;
    }
}


#define ll long long
#include<bits/stdc++.h>
using namespace std;
int main(){
      int t;cin>>t;
      while(t--){
          ll x,y,z;
          cin>>x>>y>>z;

 if(x==y)
        {
            if(z>x)
            {
                cout<<"NO\n";
            }
            else
            {
                cout<<"YES\n"<<x<<" "<<z<<" "<<max(z,1LL)<<endl;
            }
        }
        else if(x==z)
        {
            if(y>x)
            {
                cout<<"NO\n";
            }
            else
            {
                cout<<"YES\n"<<(y-1)<<" "<<x<<" "<<y<<endl;
            }
        }
        else if(y==z)
        {
            if(x>y)
            {
                cout<<"NO\n";
            }
            else
            {
                cout<<"YES\n"<<x<<" "<<max(x,1LL)<<" "<<z<<endl;
            }
        }
        else
        {
            cout<<"NO\n";
        }

    }

	return 0;
}


#include<iostream>
using namespace std;
int main(){
int t;
cin>>t;
    while (t--)
    {
        int x,y,z;
        cin>>x>>y>>z;
        if(x==y&&y==z)
        {
            cout <<"YES\n";
            cout <<x<<" "<<x<<" "<<z;
        }
        else if(x==y&&x>z)
        {
            cout<<"YES\n";
            cout<<x<<" "<<z<<" "<<z;
        }
        else if(x==z&&x>y)
        {
            cout<<"YES\n";
            cout<<x<<" "<<y<<" "<<y;
        }
        else if(y==z&&y>x)
        {
            cout<<"YES\n";
            cout<<x<<" "<<y<<" "<< x;
        }
        else
        {
            cout<<"NO";
        }
        cout<<"\n";
    }
    return 0;
}


#include<iostream>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int x,y,z;
cin>>x>>y>>z;
if(x==y&&y==z){
cout<<"YES"<<endl;
cout<<z<<" "<<z<<" "<<z;
}else if(x==z&&x>y){
cout<<"YES"<<endl;
cout<<x<<" "<<y<<" "<<y;
}
else if(x==y&&x>z){
cout<<"YES"<<endl;
cout<<x<<" "<<z<<" "<<z;
}
else if (y == z && y > x)
{
cout << "YES\n";
cout << x << " " << x << " " << y;
}
else
cout<<"NO"<<endl;

}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ul;
typedef long long int ll;
int main()
{
    fast;
    int t;
    cin >> t;
    while (t--)
    {
        ul x, y, z;
        cin >> x >> y >> z;
        if (x == y && y == z)
        {
            cout << "YES\n";
            cout << z << " " << z << " " << z;
        }
        else if (x == y && x > z)
        {
            cout << "YES\n";
            cout << x << " " << z << " " << z;
        }
        else if (x == z && x > y)
        {
            cout << "YES\n";
            cout << y << " " << x << " " << y;
        }
        else if (y == z && y > x)
        {
            cout << "YES\n";
            cout << x << " " << x << " " << y;
        }
        else
        {
            cout << "NO";
        }
        cout << "\n";
    }
    return 0;
}


#include<iostream>
using namespace std;
int main(){
int t;
cin>>t;
    while (t--)
    {
        int x, y, z;
        cin >> x >> y >> z;
        if (x == y && y == z)
        {
            cout << "YES\n";
            cout << z << " " << z << " " << z;
        }
        else if (x == y && x > z)
        {
            cout << "YES\n";
            cout << x << " " << z << " " << z;
        }
        else if (x == z && x > y)
        {
            cout << "YES\n";
            cout << y << " " << x << " " << y;
        }
        else if (y == z && y > x)
        {
            cout << "YES\n";
            cout << x << " " << x << " " << y;
        }
        else
        {
            cout << "NO";
        }
        cout << "\n";
    }
    return 0;
}


include<iostream.h>
using namespace std;
int main(){
int t;
cin>>t;
    while (t--)
    {
        int x,y,z;
        cin>>x>>y>>z;
        if(x==y&&y==z)
        {
            cout <<"YES\n";
            cout <<z<<" "<<z<<" "<<z;
        }
        else if(x==y&&x>z)
        {
            cout<<"YES\n";
            cout<<x<<" "<<z<<" "<<z;
        }
        else if(x==z&&x>y)
        {
            cout<<"YES\n";
            cout<<y<<" "<<x<<" "<<y;
        }
        else if(y==z&&y>x)
        {
            cout<<"YES\n";
            cout<<x<<" "<<x<<" "<< y;
        }
        else
        {
            cout<<"NO";
        }
        cout<<"\n";
    }
    return 0;
}


#include<iostream>
using namespace std;
int main(){
int t;
cin>>t;
    while (t--)
    {
        int x,y,z;
        cin>>x>>y>>z;
        if(x==y&&y==z)
        {
            cout <<"YES\n";
            cout <<z<<" "<<z<<" "<<z;
        }
        else if(x==y&&x>z)
        {
            cout<<"YES\n";
            cout<<x<<" "<<z<<" "<<z;
        }
        else if(x==z&&x>y)
        {
            cout<<"YES\n";
            cout<<y<<" "<<x<<" "<<y;
        }
        else if(y==z&&y>x)
        {
            cout<<"YES\n";
            cout<<x<<" "<<x<<" "<< y;
        }
        else
        {
            cout<<"NO";
        }
        cout<<"\n";
    }
    return 0;
}


include<iostream>
using namespace std;
int main(){
int t;
cin>>t;
    while (t--)
    {
        int x,y,z;
        cin>>x>>y>>z;
        if(x==y&&y==z)
        {
            cout <<"YES\n";
            cout <<z<<" "<<z<<" "<<z;
        }
        else if(x==y&&x>z)
        {
            cout<<"YES\n";
            cout<<x<<" "<<z<<" "<<z;
        }
        else if(x==z&&x>y)
        {
            cout<<"YES\n";
            cout<<y<<" "<<x<<" "<<y;
        }
        else if(y==z&&y>x)
        {
            cout<<"YES\n";
            cout<<x<<" "<<x<<" "<< y;
        }
        else
        {
            cout<<"NO";
        }
        cout<<"\n";
    }
    return 0;
}


#include<iostream>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int x,y,z;
cin>>x>>y>>z;
if(x==y&&y==z){
cout<<"YES"<<endl;
cout<<z<<z<<z;
}else if(x==z&&x>y){
cout<<"YES"<<endl;
cout<<x<<y<<y;
}
else if(x==y&&x>z){
cout<<"YES"<<endl;
cout<<x<<z<<z;
}
else
cout<<"NO"<<endl;

}
return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int t;
	cin >> t;
	vector<int> v;
	{
		for (auto &x : v) cin>>x;
		sort(v.begin(), v.end());
		if (v[1] != v[2]) {
			cout<<"NO"<<endl;
		} else {
			cout<<"YES"<<endl<<a[0]<<" "<<a[0]<<" "<<a[2]<<endl;
		}
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,x,y,z,a,b,c;
	cin>>n;
 for(int i=0;i<n;i++)
    {
        cin>>x>>y>>z;
    	if ( (x==y) && (y==z) )
		cout << "YES" <<endl<< x <<" "<< x <<" " << x <<" " << endl;
		else if ( (x==z) && (y<x) )
		cout << "YES" <<endl<< x <<" "<< y <<" " << (y-1) <<" " << endl;
		else if ( (x<y) && (y==z) )
		cout << "YES" <<endl<< x <<" "<< x <<" " << y <<" " << endl;
		else
		cout << "NO" << endl;
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int t;
	cin >> t;
	vector<int> v(3);
	for(int i=0;i<t;i++)
	{
		for (auto &x : v) cin>>x;
		sort(v.begin(), v.end());
		if (v[1] != v[2]) {
			cout<<"NO"<<endl;
		} else {
			cout<<"YES"<<endl<<v[0]<<" "<<v[0]<<" "<<v[2]<<endl;
		}
	}

	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
int main(){
int t;
cin>>t;
while(t--){
int x,y,z;
cin>>x>>y>>z;
if((x!=y)&&(y!=z))
cout<<"NO"<<endl;

else if((x==y)&&(y==z))
{
cout<<"YES"<<endl;
cout<<x<<" "<<x<<" "<<y<<endl;
}

else{
int a,b,c;
if(x!=y)
{
a=x;
b=y;
c=z;
}
else{
a=x;
b=z;
c=y;
}

if(max(a,b)==c){
cout<<"YES"<<endl;
cout<<a<<" "<<b<<" "<<min(a,b)<<endl;
}
else
cout<<"NO"<<endl;

}
}
return(0);
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int x,y,z;
cin>>x>>y>>z;
if((x!=y)&&(y!=z))
cout<<"NO"<<endl;

else if((x==y)&&(y==z))
{
cout<<"YES"<<endl;
cout<<x<<" "<<x<<" "<<y<<endl;
}

else{
int a,b,c;
if(x!=y)
{
a=x;
b=y;
c=z;
}
else{
a=x;
b=z;
c=y;
}

if(max(a,b)==c){
cout<<"YES"<<endl;
cout<<a<<" "<<b<<" "<<min(a,b)<<endl;
}
else
cout<<"NO"<<endl;

}
}
return(0);
}


#include<bits/stdc++.h>
#include<iostream>
int main(){
int t;
cin>>t;
while(t--){
int x,y,z;
cin>>x>>y>>z;
if((x!=y)&&(y!=z))
cout<<"NO"<<endl;

else if((x==y)&&(y==z))
{
cout<<"YES"<<endl;
cout<<x<<" "<<x<<" "<<y<<endl;
}

else{
int a,b,c;
if(x!=y)
{
a=x;
b=y;
c=z;
}
else{
a=x;
b=z;
c=y;
}

if(max(a,b)==c){
cout<<"YES"<<endl;
cout<<a<<" "<<b<<" "<<min(a,b)<<endl;
}
else
cout<<"NO"<<endl;

}
}
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int x,y,z;
cin>>x>>y>>z;
if((x!=y)&&(y!=z)&&(x!=z))
cout<<"NO"<<endl;

else if((x==y)&&(y==z))
{
cout<<"YES"<<endl;
cout<<x<<" "<<x<<" "<<y<<endl;
}

else{
int a,b,c;
if(x!=y)
{
a=x;
b=y;
c=z;
}
else{
a=x;
b=z;
c=y;
}

if(max(a,b)==c){
cout<<"YES"<<endl;
cout<<a<<" "<<b<<" "<<min(a,b)<<endl;
}
else
cout<<"NO"<<endl;

}
}
return(0);
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
typedef pair < ll , pair < ll , ll > > cm;

#define ff first
#define ss second
#define pb push_back
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)
#define clean cout.flush()

const ll mod = (ll)1e9+7;
const ll maxn = (ll)2e5+1100;
const int nnn = 664579+500;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

void solve(){

   ll x,y,z;
   cin >> x >> y >> z;
   vector < ll > v;
   v.pb(x) , v.pb(y) , v.pb(z);
   sort(v.begin() , v.end());
   if(v[1] == v[0]){
   	cout << "YES\n" << v[2] << ' ' << v[1] << ' ' << v[0] << '\n';
   }else if(v[2] == v[1]) 	cout << "YES\n" << v[2] << ' ' << v[0] << ' ' << 1 << '\n';
   else cout << "NO\n";

   return;
}

int main() {

   ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
typedef pair < ll , pair < ll , ll > > cm;

#define ff first
#define ss second
#define pb push_back
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)
#define clean cout.flush()

const ll mod = (ll)1e9+7;
const ll maxn = (ll)2e5+1100;
const int nnn = 664579+500;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

void solve(){

   ll x,y,z;
   cin >> x >> y >> z;
   if(x == y || x == z || y == z){
   	cout << "YES\n" << x << ' ' << y << ' ' << z << '\n';
   }else cout << '\n';

   return;
}

int main() {

   ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
typedef pair < ll , pair < ll , ll > > cm;

#define ff first
#define ss second
#define pb push_back
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)
#define clean cout.flush()

const ll mod = (ll)1e9+7;
const ll maxn = (ll)2e5+1100;
const int nnn = 664579+500;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

void solve(){

   ll x,y,z;
   cin >> x >> y >> z;
   if(x == y || x == z || y == z){
   	cout << "YES\n" << x << ' ' << y << ' ' << z << '\n';
   }else cout << "NO\n";

   return;
}

int main() {

   ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
typedef pair < ll , pair < ll , ll > > cm;

#define ff first
#define ss second
#define pb push_back
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)
#define clean cout.flush()

const ll mod = (ll)1e9+7;
const ll maxn = (ll)2e5+1100;
const int nnn = 664579+500;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

void solve(){

   ll x,y,z;
   cin >> x >> y >> z;
   vector < ll > v;
   v.pb(x) , v.pb(y) , v.pb(z);
   sort(v.begin() , v.end());
   if(v[2] == v[1]) 	cout << "YES\n" << v[2] << ' ' << v[0] << ' ' << 1 << '\n';
   else cout << "NO\n";

   return;
}

int main() {

   ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
typedef pair < ll , pair < ll , ll > > cm;

#define ff first
#define ss second
#define pb push_back
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)
#define clean cout.flush()

const ll mod = (ll)1e9+7;
const ll maxn = (ll)2e5+1100;
const int nnn = 664579+500;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

void solve(){

   ll x,y,z;
   cin >> x >> y >> z;
   vector < ll > v;
   v.pb(x) , v.pb(y) , v.pb(z);
   sort(v.begin() , v.end());
   if(v[1] == v[0]){
   	cout << "YES\n" << v[2] << ' ' << v[0] << ' ' << 1 << '\n';
   }else if(v[2] == v[1]) 	cout << "YES\n" << v[2] << ' ' << v[0] << ' ' << 1 << '\n';
   else cout << "NO\n";

   return;
}

int main() {

   ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}

    return 0;
}


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

int n;

int x,y,z;
int a,b,c;
int arr[3];
int flag[2];

bool solve(){
    if(x != y){
        b = x; c = y;
        if(max(b,c) != z){

            return false;
        }
        arr[0] = b ; arr[1] = c ; arr[2] = min(b,c) ;
        return true;
    }
    else{
        a = x;

        if(z > a){
            return false;
        }

        b = z;
        c = z;

        arr[0] = a; arr[1] = b; arr[2] = c;

    }
}

int main(void){
    cin>>n;
    for(int i= 0;i<n;i++){
        cin>>x>>y>>z;
        if(solve()){
            cout<<"YES"<<"\n";
            cout<< arr[0]<<" "<<arr[1]<<" "<<arr[2]<<"\n";
        }
        else{
            cout<<"NO"<<"\n";
        }
    }
    return 0;
}


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

int n;
int a,b,c;
int arr[3];

bool solve(){
    sort(arr,arr+3,greater<int>());

    if(arr[0] != arr[1])
        return false;
    a = arr[0] ; b = arr[2]; c = 1 ;

}

int main(void){
    cin>>n;
    for(int i= 0;i<n;i++){
        cin>>arr[0]>>arr[1]>>arr[2];
        if(solve()){
            cout<<"YES"<<"\n";
            cout<<a<<" "<<b<<" "<<c<<"\n";
        }
        else
        {
            cout<<"NO"<<"\n";
        }
    }
    return 0;
}


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

int n;

int x,y,z;
int a,b,c;
int arr[3];

bool solve(){
    b = x; c = y;
    if(max(b,c) != z){
        return false;
    }
    arr[0] = b ; arr[1] = c ; arr[2] = -1 ;
    return true;
}

int main(void){
    cin>>n;
    for(int i= 0;i<n;i++){
        cin>>x>>y>>z;
        if(solve()){
            cout<<"YES"<<"\n";
            cout<< arr[0]<<" "<<arr[1]<<" "<<arr[2]<<"\n";
        }
        else{
            cout<<"NO"<<"\n";
        }
    }
    return 0;
}


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

int n;

int x,y,z;
int a,b,c;
int arr[3];

bool solve(){
    b = x; c = y;
    if(max(b,c) != z){
        return false;
    }
    arr[0] = b ; arr[1] = c ; arr[2] = z ;
    return true;
}

int main(void){
    cin>>n;
    for(int i= 0;i<n;i++){
        cin>>x>>y>>z;
        if(solve()){
            cout<<"YES"<<"\n";
            cout<< arr[0]<<" "<<arr[1]<<" "<<arr[2]<<"\n";
        }
        else{
            cout<<"NO"<<"\n";
        }
    }
    return 0;
}


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

int n;
int a,b,c;
int arr[3];

bool solve(){
    sort(arr,arr+3,greater<int>());

    if(arr[0] != arr[1])
        return false;
    a = arr[0] ; b = arr[2]; c = 1 ;
    return true;
}

int main(void){
    cin>>n;
    for(int i= 0;i<n;i++){
        cin>>arr[0]>>arr[1]>>arr[2];
        if(solve()){
            cout<<"YES"<<"\n";
            cout<<a<<" "<<b<<" "<<c<<"\n";
        }
        else
        {
            cout<<"NO"<<"\n";
        }
    }
    return 0;
}


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

int n;

int x,y,z;
int a,b,c;
int arr[3];
int flag[2];

bool solve(int x,int y,int z){
    b = x; c = y;
    if(max(b,c) != z){
        if(!flag[0]){
            flag[0] = true;
            solve(y,x,z);
        }
        if(!flag[1]){
            flag[1] = true;
            solve(x,z,y);
        }
        return false;
    }
    arr[0] = b ; arr[1] = c ; arr[2] = min(b,c) ;
    return true;
}

int main(void){
    cin>>n;
    for(int i= 0;i<n;i++){
        cin>>x>>y>>z;
        if(solve(x,y,z)){
            cout<<"YES"<<"\n";
            cout<< arr[0]<<" "<<arr[1]<<" "<<arr[2]<<"\n";
        }
        else{
            cout<<"NO"<<"\n";
        }
    }
    return 0;
}


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

int n;

int x,y,z;
int a,b,c;
int arr[3];

bool solve(){
    b = x; c = y;
    if(max(b,c) != z){
        return false;
    }
    arr[0] = b ; arr[1] = c ; arr[2] = min(b,c);
    return true;
}

int main(void){
    cin>>n;
    for(int i= 0;i<n;i++){
        cin>>x>>y>>z;
        if(solve()){
            cout<<"YES"<<"\n";
            cout<< arr[0]<<" "<<arr[1]<<" "<<arr[2]<<"\n";
        }
        else{
            cout<<"NO"<<"\n";
        }
    }
    return 0;
}


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

int n;
int x,y,z;
int a,b,c;
int arr[3];

bool solve(){
    if(x > y) swap(x,y);
    a = x; b = x; c = y;

    if(max(x,y) == z)
        return true;
    else
    {
        return false;
    }

}

int main(void){
    cin>>n;
    for(int i= 0;i<n;i++){
        cin>>x>>y>>z;
        if(solve()){
            cout<<"YES"<<"\n";
            cout<<a<<" "<<b<<" "<<c<<"\n";
        }
        else
        {
            cout<<"NO"<<"\n";
        }
    }
    return 0;
}


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

int n;

int x,y,z;
int a,b,c;
int arr[3];

bool solve(){
    b = x; c = y;
    if(max(b,c) != z){
        return false;
    }
    arr[0] = b ; arr[1] = c ; arr[2] = min(b,c)-1;
    return true;
}

int main(void){
    cin>>n;
    for(int i= 0;i<n;i++){
        cin>>x>>y>>z;
        if(solve()){
            cout<<"YES"<<"\n";
            cout<< arr[0]<<" "<<arr[1]<<" "<<arr[2]<<"\n";
        }
        else{
            cout<<"NO"<<"\n";
        }
    }
    return 0;
}