content: import java.io.*;
  import java.math.*;
  import java.security.*;
  import java.text.*;
  import java.util.*;
  import java.util.concurrent.*;
  import java.util.regex.*;
  
  public class Solution {
  
      static class DoublyLinkedListNode {
          public int data;
          public DoublyLinkedListNode next;
          public DoublyLinkedListNode prev;
  
          public DoublyLinkedListNode(int nodeData) {
              this.data = nodeData;
              this.next = null;
              this.prev = null;
          }
      }
  
      static class DoublyLinkedList {
          public DoublyLinkedListNode head;
          public DoublyLinkedListNode tail;
  
          public DoublyLinkedList() {
              this.head = null;
              this.tail = null;
          }
  
          public void insertNode(int nodeData) {
              DoublyLinkedListNode node = new DoublyLinkedListNode(nodeData);
  
              if (this.head == null) {
                  this.head = node;
              } else {
                  this.tail.next = node;
                  node.prev = this.tail;
              }
  
              this.tail = node;
          }
      }
  
      public static void printDoublyLinkedList(DoublyLinkedListNode node, String sep, BufferedWriter bufferedWriter) throws IOException {
          while (node != null) {
              bufferedWriter.write(String.valueOf(node.data));
  
              node = node.next;
  
              if (node != null) {
                  bufferedWriter.write(sep);
              }
          }
      }
  
      //Method to reverse a doubly linked list
      static DoublyLinkedListNode reverse(DoublyLinkedListNode head) {
          //If head is null  or the DLL contains only one node return head
          if (head == null || head.next == null) {
              return head;
          }
          //Maintain three DLL nodes 
          DoublyLinkedListNode prev = null;   //keeps record of previous node
          DoublyLinkedListNode curr = head;   //keeps record of current node
          DoublyLinkedListNode next = null;   //keeps record of next node
          //Traverse through the linked list and
          //At each point replace next of current 
          //with previous of current node
          while (curr != null) {
              next = curr.next;
              curr.next = prev;
              curr.prev = next;
              prev = curr;    //Set previous to current
              curr = next;    //Move ahead
          }
          //Finally return previous which will be our new head
          return prev;
      }
  
      private static final Scanner scanner = new Scanner(System.in);
  
      public static void main(String[] args) throws IOException {
          BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
  
          int t = scanner.nextInt();
          scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
  
          for (int tItr = 0; tItr < t; tItr++) {
              DoublyLinkedList llist = new DoublyLinkedList();
  
              int llistCount = scanner.nextInt();
              scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
  
              for (int i = 0; i < llistCount; i++) {
                  int llistItem = scanner.nextInt();
                  scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
  
                  llist.insertNode(llistItem);
              }
  
              DoublyLinkedListNode llist1 = reverse(llist.head);
  
              printDoublyLinkedList(llist1, " ", bufferedWriter);
              bufferedWriter.newLine();
          }
  
          bufferedWriter.close();
  
          scanner.close();
      }
  }
  