import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author chaku
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            long k = in.nextLong(), d = in.nextLong(), t = 2 * in.nextLong();
            long v1 = (k + d - 1) / d;
            long tsp = v1 * d + k;
            long totCyc = t / tsp;
            long ext = t % tsp;
            if (ext <= 2 * k) {
                out.println((double) (totCyc * v1 * d) + (double) ext / 2.0);
            } else {
                out.println((double) (totCyc * v1 * d) + k + (ext - 2 * k));
            }
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

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

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

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

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

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author chaku
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            long k = in.nextLong(), d = in.nextLong(), t = in.nextLong();
            long hcf = gcd(k, d);
            //System.out.println(hcf);
            double val = 0;
            double ans = 0;
            for (long i = 0; ; i += hcf) {
                boolean ch1 = false;
                if ((i / k + 1) % 2 == 0) ch1 = true;
                boolean ch2 = false;
                if ((i / d + 1) % 2 == 0) ch2 = true;
                if (ch1 && ch2) {
                    // System.out.println(i);
                    double curr = (double) hcf / (2 * t);
                    if (curr + val > 1) {
                        ans = i - hcf + (1 - val) * 2 * t;
                        break;
                    }
                    val += curr;

                } else {
                    //System.out.println("a:"+i);
                    double curr = (double) hcf / (t);
                    if (curr + val > 1) {
                        ans = i + (1 - val) * t;
                        break;
                    }
                    val += curr;
                }
            }
            out.println(ans);
        }

        static long gcd(long a, long b) {
            if (a == 0) return b;
            return gcd(b % a, a);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

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

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

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

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

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author chaku
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            long k = in.nextLong(), d = in.nextLong(), t = in.nextLong();
            long hcf = gcd(k, d);
            //System.out.println(hcf);
            double val = 0;
            double ans = 0;
            for (long i = 0; ; i += hcf) {
                boolean ch1 = false;
                if ((i / k + 1) % 2 == 0) ch1 = true;
                boolean ch2 = false;
                if ((i / d + 1) % 2 == 0) ch2 = true;
                if (ch1 && ch2) {

                    double curr = (double) hcf / (2 * t);
                    //System.out.println(i+" "+val+" "+curr);
                    if (Math.abs(1 - val - curr) < 0.000000001) {
                        ans = i;
                        break;
                    }
                    if (curr + val >= 1) {
                        ans = i + (1 - val) * 2 * t;
                        break;
                    }
                    val += curr;

                } else {
                    //System.out.println("a:"+i);
                    double curr = (double) hcf / (t);
                    // System.out.println("a:"+i+" "+val+" "+curr);
                    if (Math.abs(1 - val - curr) < 0.000000001) {
                        ans = i;
                        break;
                    }
                    if (curr + val >= 1) {
                        ans = i + (1 - val) * t;
                        break;
                    }
                    val += curr;

                }
            }
            out.println(ans);
        }

        static long gcd(long a, long b) {
            if (a == 0) return b;
            return gcd(b % a, a);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

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

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

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

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

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}


import java.io.BufferedReader;
// import java.io.FileInputStream;
// import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

import static java.util.Arrays.copyOf;
import static java.util.Arrays.fill;
import static java.util.Arrays.sort;
import static java.util.Collections.reverseOrder;
import static java.util.Collections.sort;

public class Main {
    private FastScanner in;
    private PrintWriter out;

    private void solve() throws IOException {
        long k = in.nextLong(), d = in.nextLong(), t = in.nextLong();
        long c = 2 * k + (d - k % d) % d;
        long time = ((k - 1) / d + 1) * d;
        long x = 2 * t / c;
        long ans = time * x;
        long ost = 2 * t - x * c;
        if (ost <= 2 * k)
            out.println(ans + (double) ost / 2);
        else
            out.println(ans + k + (double) (ost - 2 * k));
    }

    class FastScanner {
        StringTokenizer st;
        BufferedReader br;

        FastScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        boolean hasNext() throws IOException {
            return br.ready() || (st != null && st.hasMoreTokens());
        }

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

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

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

        String nextLine() throws IOException {
            return br.readLine();
        }

        boolean hasNextLine() throws IOException {
            return br.ready();
        }
    }

    private void run() throws IOException {
        in = new FastScanner(System.in); // new FastScanner(new FileInputStream(".in"));
        out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream(".out"));

        solve();

        out.flush();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemCSaveEnergy solver = new ProblemCSaveEnergy();
        solver.solve(1, in, out);
        out.close();
    }

    static class ProblemCSaveEnergy {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long k = in.nextLong(), d = in.nextLong(), t = in.nextLong();
            long K = (long) Math.ceil((double) k / d) * d;
            long a = k, b = K - k;
            long _k = (2 * t) / (2 * a + b);
            long needed = 2 * t - _k * (2 * a + b);
            double answer = _k * K;
            if (needed <= 2 * a) answer += (double) needed / 2;
            else answer += a + (needed - 2 * a);
            out.println(answer);
        }

    }

    static class InputReader {
        private StringTokenizer tokenizer;
        private BufferedReader reader;

        public InputReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

        private void fillTokenizer() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }

        public String next() {
            fillTokenizer();
            return tokenizer.nextToken();
        }

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

    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 * @author pttrung
 */
public class C_Round_467_Div2 {

    public static long MOD = 1000000007;

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        long k = in.nextLong();
        long d = in.nextLong();
        long t = in.nextLong();
        double off, on;
        double cycle;
        if (k <= d) {
            off = (d - k)*0.5;
            on = k;
            cycle = d;
        } else {
            long tmp = k / d;
            if (tmp * d < k) {
                tmp++;
            }
            off = (tmp * d - k)*0.5;
            on = k;
            cycle = tmp*d;
        }
        double need = t;
        need /= (off + on);
        need = Math.floor(need);
        double left = t - need*(off + on);
        //System.out.println(left + " " + " " + need);
        double re = need*cycle;
        if(left <= k){
            re += left;
        }else{
            re += k;
            left -= k;
            re += 2*left;
        }
        out.println(re);
        out.close();
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.math.*;
import java.util.InputMismatchException;
public class solution
{
	public static void main(String args[]) throws Exception
		{
			InputReader sc = new InputReader(System.in);
			PrintWriter out = new PrintWriter(System.out);
			double k = sc.nextLong();
			double d = sc.nextLong();
			double t = sc.nextLong();
			if(k%d==0||d%k==0)
			{
				out.println(t);
			}
			else
			{
				double k1 = (((int)(k/d)+1)*d-k)/2;
				double ans = 0;
				while(true)
				{
					if(t<=k)
					{
						ans+=t;
						break;
					}
					ans+=k;
					t-=k;
					if(t<=k1)
					{
						ans+=2*t;
						break;
					}
					ans+=2*k1;
					t-=k1;
				}
				out.println(ans);
			}
			out.close();
		}
	static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

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

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

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

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int[] readCharCount() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int[] map = new int[256];
            do {
                int val = c ;
                map[val]++;
                c = snext();
            } while (!isSpaceChar(c));
            return map;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.math.*;
import java.util.InputMismatchException;
public class solution
{
	public static void main(String args[]) throws Exception
		{
			InputReader sc = new InputReader(System.in);
			PrintWriter out = new PrintWriter(System.out);
			double k = sc.nextLong();
			double d = sc.nextLong();
			double t = sc.nextLong();
			if(k%d==0)
			{
				out.println(t);
			}
			else
			{
				double k1 = (((int)(k/d)+1)*d-k)/2;
				double ans = 0;
				while(true)
				{
					if(t<=k)
					{
						ans+=t;
						break;
					}
					ans+=k;
					t-=k;
					if(t<=k1)
					{
						ans+=2*t;
						break;
					}
					ans+=2*k1;
					t-=k1;
				}
				out.println(ans);
			}
			out.close();
		}
	static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

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

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

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

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int[] readCharCount() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int[] map = new int[256];
            do {
                int val = c ;
                map[val]++;
                c = snext();
            } while (!isSpaceChar(c));
            return map;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.math.*;
import java.util.InputMismatchException;
public class solution
{
	public static void main(String args[]) throws Exception
		{
			InputReader sc = new InputReader(System.in);
			PrintWriter out = new PrintWriter(System.out);
			double k = sc.nextLong();
			double d = sc.nextLong();
			double t = sc.nextLong();
			if(k%d==0)
			{
				out.println(t);
			}
			else
			{
				double k1 = (((long)(k/d)+1)*d-k)/2;
				double ans = 0;
				long x = (long)(t/(k+k1));
				ans = x*(k+2*k1);
				t-=x*(k+k1);
				while(true)
				{
					if(t<=k)
					{
						ans+=t;
						break;
					}
					ans+=k;
					t-=k;
					if(t<=k1)
					{
						ans+=2*t;
						break;
					}
					ans+=2*k1;
					t-=k1;
				}
				out.println(ans);
			}
			out.close();
		}
	static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

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

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

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

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int[] readCharCount() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int[] map = new int[256];
            do {
                int val = c ;
                map[val]++;
                c = snext();
            } while (!isSpaceChar(c));
            return map;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

}


import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

	public static void main(String [] args) throws IOException{
	    Scanner sc = new Scanner(System.in);
	    long k, d;
	    while(sc.hasNext()){
	        k = sc.nextLong();
	        d = sc.nextLong();
	        BigDecimal t = sc.nextBigDecimal();
	        BigDecimal onTime, offTime, spendTime, usefulTime, ans;
	        if(k % d != 0){
	            onTime = new BigDecimal(k);
	            offTime = new BigDecimal(d-k%d);
	        }else{
	            onTime = new BigDecimal(k);
                offTime = new BigDecimal(0);
	        }
	        spendTime = onTime.add(offTime);
	        usefulTime = onTime.add(offTime.multiply(new BigDecimal(0.5)));
	        long times = t.divide(usefulTime, 20, RoundingMode.CEILING).longValue();
	        ans = new BigDecimal(times).multiply(spendTime);
	        t = t.subtract(new BigDecimal(times).multiply(usefulTime));
	        if(t.compareTo(onTime) == -1){
	            ans = ans.add(t);
	        }else{
	            ans = ans.add(onTime);
	            t = t.subtract(onTime);
	            ans = ans.add(t.multiply(new BigDecimal(2)));
	        }
	        System.out.println(ans);
	    }
	}
}


import java.util.*;
public class algo3
{
    public static void main(String args[])
    {
        Scanner ex=new Scanner(System.in);
        long k=ex.nextLong();
        long d=ex.nextLong();
        long t=ex.nextLong();
        t=2*t;
        double ans=0;
        if(k%d==0||t<=k)
        System.out.println(t/2);
        else if(k<d)
        {
            long num=2*k+d-k;
            ans=d*(t/num);
            long rem=t%num;
            if(rem<=2*k)
            {
                ans=ans+((double)(rem))/2.0;
                System.out.println(ans);
            }
            else
            {
                ans=ans+k;
                rem=rem-2*k;
                ans=ans+rem;
                System.out.println(ans);
            }
        }
        else
        {
            long num=2*k+(d-k%d);
            ans=(k+d-k%d)*(t/num);
            long rem=t%num;
            if(rem<=2*k)
            {
                ans=ans+((double)(rem))/2.0;
                System.out.println(ans);
            }
            else
            {
                ans=ans+k;
                rem=rem-2*k;
                ans=ans+rem;
                System.out.println(ans);
            }
        }
    }
}


import java.util.*;
public class algo3
{
    public static void main(String args[])
    {
        Scanner ex=new Scanner(System.in);
        long k=ex.nextLong();
        long d=ex.nextLong();
        long t=ex.nextLong();
        t=2*t;
        double ans=0;
        if(k%d==0||t<=k)
        System.out.println(t/2);
        else if(k<d)
        {
            long num=2*k+d%k;
            ans=(k+d%k)*(t/num);
            long rem=t%num;
            if(rem<=2*k)
            {
                ans=ans+((double)(rem))/2.0;
                System.out.println(ans);
            }
            else
            {
                ans=ans+k;
                rem=rem-2*k;
                ans=ans+rem;
                System.out.println(ans);
            }
        }
        else
        {
            long num=2*k+(d-k%d);
            ans=(k+d-k%d)*(t/num);
            long rem=t%num;
            if(rem<=2*k)
            {
                ans=ans+((double)(rem))/2.0;
                System.out.println(ans);
            }
            else
            {
                ans=ans+k;
                rem=rem-2*k;
                ans=ans+rem;
                System.out.println(ans);
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/*
 public class _937C {

 }

 */
public class _937C {
  public void solve() throws FileNotFoundException {
    InputStream inputStream = System.in;

    InputHelper in = new InputHelper(inputStream);

    // actual solution
    double k = in.readLong();
    double d = in.readLong();
    double t = in.readLong();

    if (k % d == 0) {
      System.out.println(t);
      return;
    } else if (d < k) {
      long tim = (long) ((k + d - 1) / d);
      double tt = tim * d;

      double ct = k + (tt - k) / 2;

      double cans = tt;

      if (ct >= t) {
        if (k >= t) {
          System.out.println(t);
          return;
        } else {
          System.out.println(k + (t - k) * 2);
          return;
        }
      } else {
        double at = (long) (t / ct);
        double ans = cans * at;
        t -= at * ct;
        if (k >= t) {
          System.out.println(ans + t);
          return;
        } else {
          System.out.println(ans + k + (t - k) * 2);
          return;
        }
      }
    } else {
      double ct = k + (d - k) / 2;

      double cans = d;

      if (ct >= t) {
        if (k >= t) {
          System.out.println(t);
          return;
        } else {
          System.out.println(k + (t - k) * 2);
          return;
        }
      } else {
        double at = (long) (t / ct);
        double ans = cans * at;
        t -= at * ct;
        if (k >= t) {
          System.out.println(ans + t);
          return;
        } else {
          System.out.println(ans + k + (t - k) * 2);
          return;
        }
      }
    }
    // end here
  }

  public static void main(String[] args) throws FileNotFoundException {
    (new _937C()).solve();
  }

  class InputHelper {
    StringTokenizer tokenizer = null;
    private BufferedReader bufferedReader;

    public InputHelper(InputStream inputStream) {
      InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
      bufferedReader = new BufferedReader(inputStreamReader, 16384);
    }

    public String read() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          String line = bufferedReader.readLine();
          if (line == null) {
            return null;
          }
          tokenizer = new StringTokenizer(line);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }

      return tokenizer.nextToken();
    }

    public Integer readInteger() {
      return Integer.parseInt(read());
    }

    public Long readLong() {
      return Long.parseLong(read());
    }
  }
}


import java.util.*;
import java.io.*;
import java.text.*;
public class Main{
    //SOLUTION BEGIN
    //Into the Hardware Mode
    void pre() throws Exception{}
    void solve(int TC)throws Exception{
        long k = nl(), d = nl(), t = nl();
        double D = ((long)(k+d-1)/d)*d;

        double n = k+(D-k)/2.0;
        double ans = ((long)(t*1.0/n))*D;
        double T = (double)t%n;
        if(T <= k){
            ans += T;
        }else{
            ans += k;
            T -= k;
            ans += T*2;
        }
        pn(ans);
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    void exit(boolean b){if(!b)System.exit(0);}
    long IINF = (long)1e18, mod = (long)1e8+7;
    final int INF = (int)1e9, MX = (int)2e6+5;
    DecimalFormat df = new DecimalFormat("0.00000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-6;
    static boolean multipleTC = false, memory = false, fileIO = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        if(fileIO){
            in = new FastReader("input.txt");
            out = new PrintWriter("output.txt");
        }else {
            in = new FastReader();
            out = new PrintWriter(System.out);
        }
        //Solution Credits: Taranpreet Singh
        int T = (multipleTC)?ni():1;
        pre();
        for(int t = 1; t<= T; t++)solve(t);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }

    int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

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


//_Hala Madrid_//

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

typedef long long            ll;
typedef double               db;
typedef long double          ldb;
typedef vector<int>          vi;
typedef pair<int, int>       pii;
#define fio                  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,start,end)     for(ll i=start;i<=end;i++)
#define FORD(i,start,end)    for(ll i=start;i>=end;i--)
#define br                   cout<<"\n"
#define test(t)              int t;cin>>t;while(t--)
#define ini(a,n)             memset(a,n,sizeof(a))
#define rz                   return 0
#define all(s)               s.begin(),s.end()
#define sz                   size()
#define pb                   push_back
#define F                    first
#define S                    second

const int mod=1e9+7;

void solve(){
    bool flag=0,flag1=0;
    int m,n,k,l,r,sum=0,ans=0,pos1,c1=0,c2=0,c3=0,c4=0,x,y,z,cnt=0,mx=0,mn=INT_MAX;
    string s,t,s1,s2;
    string str="";
    vi v;
    cin>>n;
    int pos[n+5];
    ini(pos,-1);
    FOR(i,1,n){
        cin>>x;
        if(pos[x]==-1)
        pos[x]=i;
        else{
            if(pos[x]<i-1)
            flag=1;
        }
    }
    if(flag)
    cout<<"YES";
    else
    cout<<"NO";
    br;
}
int main(){
    fio
    bool notc=1;
    int t=1;
    if(notc){
        cin>>t;
    }
    while(t--){

        #ifdef _DEBUG
	        freopen("input.txt", "r", stdin);
	        freopen("output.txt", "w", stdout);
        #endif

        solve();
    }
    rz;
}


//_Hala Madrid_//

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

typedef long long            ll;
typedef double               db;
typedef long double          ldb;
typedef vector<int>          vi;
typedef pair<int, int>       pii;
#define fio                  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,start,end)     for(ll i=start;i<=end;i++)
#define FORD(i,start,end)    for(ll i=start;i>=end;i--)
#define br                   cout<<"\n"
#define test(t)              int t;cin>>t;while(t--)
#define ini(a,n)             memset(a,n,sizeof(a))
#define rz                   return 0
#define all(s)               s.begin(),s.end()
#define sz                   size()
#define pb                   push_back
#define F                    first
#define S                    second

const int mod=1e9+7;

bool palindrome(int arr[], int m, int n)
{
    // Initialise flag to zero.
    bool flag = 0;

    // Loop till array size n/2.
    for (int i = m; i <= n / 2 && n != 0; i++) {

        // Check if first and last element are different
        // Then set flag to 1.
        if (arr[i] != arr[n - i - 1]) {
            flag = 1;
            break;
        }
    }

    // If flag is set then print Not Palindrome
    // else print Palindrome.
    return flag;
}
void solve(){
    bool flag=0,flag1=0;
    int m,n,k,l,r,sum=0,ans=0,pos,pos1,c1=0,c2=0,c3=0,c4=0,x,y,z,cnt=0,mx=0,mn=INT_MAX;
    string s,t,s1,s2;
    string str="";
    //vi a(n),b(n);
    cin>>n;
    int a[n],b[n];
    FOR(i,0,n-1){
        cin>>a[i];
        b[i]=a[i];
    }
    if(n<3)
    cout<<"NO";
    else{
        FORD(i,n-2,0){
            FOR(j,i+1,n-1){
                if(a[i]==a[j]){
                    x=i;
                    y=j;
                    flag=1;
                }
            }
        }
        cout<<x<<" "<<y;
        if(!flag)
        cout<<"NO";
        else{
            FOR(i,x+1,y-1){
                if(a[i]!=a[x])
                flag1=1;
            }
            if(flag1)
            cout<<"YES";
            else
            cout<<"NO";
        }

    }
    br;
}
int main(){
    fio
    bool notc=1;
    int t=1;
    if(notc){
        cin>>t;
    }
    while(t--){

        #ifdef _DEBUG
	        freopen("input.txt", "r", stdin);
	        freopen("output.txt", "w", stdout);
        #endif

        solve();
    }
    rz;
}


//_Hala Madrid_//

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

typedef long long            ll;
typedef double               db;
typedef long double          ldb;
typedef vector<int>          vi;
typedef pair<int, int>       pii;
#define fio                  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,start,end)     for(ll i=start;i<=end;i++)
#define FORD(i,start,end)    for(ll i=start;i>=end;i--)
#define br                   cout<<"\n"
#define test(t)              int t;cin>>t;while(t--)
#define ini(a,n)             memset(a,n,sizeof(a))
#define rz                   return 0
#define all(s)               s.begin(),s.end()
#define sz                   size()
#define pb                   push_back
#define F                    first
#define S                    second

const int mod=1e9+7;

void solve(){
    bool flag=0,flag1=0;
    int m,n,k,l,r,sum=0,ans=0,pos,pos1,c1=0,c2=0,c3=0,c4=0,x,y,z,cnt=0,mx=0,mn=INT_MAX;
    string s,t,s1,s2;
    string str="";
    //vi a(n),b(n);
    cin>>n;
    int a[n],b[n];
    FOR(i,0,n-1){
        cin>>a[i];
        b[i]=a[i];
    }

        FORD(i,n-2,0){
            FOR(j,i+1,n-1){
                if(a[i]==a[j]){
                    x=i;
                    y=j;
                    flag=1;
                }
            }
        }
        //cout<<x<<" "<<y;
        if(!flag)
        cout<<"NO";
        else{
            if(y-x>1)
            cout<<"YES";
            else
            cout<<"NO";
        }

    br;
}
int main(){
    fio
    bool notc=1;
    int t=1;
    if(notc){
        cin>>t;
    }
    while(t--){

        #ifdef _DEBUG
	        freopen("input.txt", "r", stdin);
	        freopen("output.txt", "w", stdout);
        #endif

        solve();
    }
    rz;
}


//_Hala Madrid_//

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

typedef long long            ll;
typedef double               db;
typedef long double          ldb;
typedef vector<int>          vi;
typedef pair<int, int>       pii;
#define fio                  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,start,end)     for(ll i=start;i<=end;i++)
#define FORD(i,start,end)    for(ll i=start;i>=end;i--)
#define br                   cout<<"\n"
#define test(t)              int t;cin>>t;while(t--)
#define ini(a,n)             memset(a,n,sizeof(a))
#define rz                   return 0
#define all(s)               s.begin(),s.end()
#define sz                   size()
#define pb                   push_back
#define F                    first
#define S                    second

const int mod=1e9+7;

bool palindrome(int arr[], int m, int n)
{
    // Initialise flag to zero.
    bool flag = 0;

    // Loop till array size n/2.
    for (int i = m; i <= n / 2 && n != 0; i++) {

        // Check if first and last element are different
        // Then set flag to 1.
        if (arr[i] != arr[n - i - 1]) {
            flag = 1;
            break;
        }
    }

    // If flag is set then print Not Palindrome
    // else print Palindrome.
    return flag;
}
void solve(){
    bool flag=0,flag1=0;
    int m,n,k,l,r,sum=0,ans=0,pos,pos1,c1=0,c2=0,c3=0,c4=0,x,y,z,cnt=0,mx=0,mn=INT_MAX;
    string s,t,s1,s2;
    string str="";
    //vi a(n),b(n);
    cin>>n;
    int a[n],b[n];
    FOR(i,0,n-1){
        cin>>a[i];
        b[i]=a[i];
    }
    if(n<3)
    cout<<"NO";
    else{
        FORD(i,n-2,0){
            FOR(j,i+1,n-1){
                if(a[i]==a[j]){
                    x=i;
                    y=j;
                    flag=1;
                }
            }
        }
        //cout<<x<<" "<<y;
        if(!flag)
        cout<<"NO";
        else{
            FOR(i,x+1,y-1){
                if(a[i]!=a[x])
                flag1=1;
            }
            if(flag1)
            cout<<"YES";
            else
            cout<<"NO";
        }

    }
    br;
}
int main(){
    fio
    bool notc=1;
    int t=1;
    if(notc){
        cin>>t;
    }
    while(t--){

        #ifdef _DEBUG
	        freopen("input.txt", "r", stdin);
	        freopen("output.txt", "w", stdout);
        #endif

        solve();
    }
    rz;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[n+1]={0},b[n+1]={0},x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
			b[a[j]]++;
			if(b[a[j]]>1){
				if(a[j]!=a[j-1]){
					x=1;
				}else if(a[j]==a[j+1])
				    x=1;
			}
		}
		if(x==0)
			cout<<"NO"<<endl;
			else cout<<"YES"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[n],b[n],x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
			b[a[j]]++;
			if(b[a[j]]>1)
				if(a[j]!=a[j-1]){
					cout<<"YES"<<endl;
					x=1;
					break;
				}
		}
		if(x==0)
			cout<<"NO"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[n],b[n]={0},x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
			b[a[j]]++;
			if(b[a[j]]>1)
				if(a[j]!=a[j-1]){
					cout<<"YES"<<endl;
					x=1;
					break;
				}
		}
		if(x==0)
			cout<<"NO"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[n]={0},b[n]={0},x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
			b[a[j]]++;
			if(b[a[j]]>1)
				if(a[j]!=a[j-1]){
					cout<<"YES"<<endl;
					x=11;
					break;
				}
		}
		if(x==0)
			cout<<"NO"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[n],b[n+1]={0},x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
			b[a[j]]++;
			if(b[a[j]]>1)
				if(a[j]!=a[j-1]){
					cout<<"YES"<<endl;
					x=1;
					break;
				}
		}
		if(x==0)
			cout<<"NO"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[n],b[n+1]={0},x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
			b[a[j]]++;
			if(b[a[j]]>1)
				if(a[j]!=a[j-1]){
					x=1;
				}
		}
		if(x==0)
			cout<<"NO"<<endl;
			else cout<<"YES"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[5001]={0},b[5002]={0},x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
			b[a[j]]++;
			if(b[a[j]]>1)
				if(a[j]!=a[j-1]){
					cout<<"YES"<<endl;
					x=1;
					break;
				}
		}
		if(x==0)
			cout<<"NO"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[n],b[n+1],x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
			b[a[j]]++;
			if(b[a[j]]>1)
				if(a[j]!=a[j-1]){
					cout<<"YES"<<endl;
					x=1;
					break;
				}
		}
		if(x==0)
			cout<<"NO"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[n]={0},b[n]={0},x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
			b[a[j]]++;
			ll m = 0;
			m=b[a[j]];
			if(m>1)
				if(a[j]!=a[j-1]){
					cout<<"YES"<<endl;
					x=1;
					break;
				}
		}
		if(x==0)
			cout<<"NO"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[n],b[n+1],x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
			b[a[j]]++;
			if(b[a[j]]>1 && j>0)
				if(a[j]!=a[j-1]){
					cout<<"YES"<<endl;
					x=1;
					break;
				}
		}
		if(x==0)
			cout<<"NO"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[n]={0},b[n]={0},x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
			b[a[j]]++;
			if(b[a[j]]>1)
				if(a[j]!=a[j-1]){
					cout<<"YES"<<endl;
					x=1;
					break;
				}
		}
		if(x==0)
			cout<<"NO"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[5000]={0},b[5001]={0},x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
			b[a[j]]++;
			if(b[a[j]]>1)
				if(a[j]!=a[j-1]){
					cout<<"YES"<<endl;
					x=1;
					break;
				}
		}
		if(x==0)
			cout<<"NO"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll int
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[n]={0},b[n]={0},x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
			b[a[j]]++;
			if(b[a[j]]>1)
				if(a[j]!=a[j-1]){
					cout<<"YES"<<endl;
					x=1;
					break;
				}
		}
		if(x==0)
			cout<<"NO"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[n]={0},b[n]={0},x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
			b[a[j]]++;
			ll m = b[a[j]];
			if(m>1)
				if(a[j]!=a[j-1]){
					cout<<"YES"<<endl;
					x=1;
					break;
				}
		}
		if(x==0)
			cout<<"NO"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[n+1]={0},b[n+1]={0},x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
		}
		for(ll j=0; j<n ;j++){
			b[a[j]]++;
			if(b[a[j]]>1){
				if(a[j]!=a[j-1]){
					x=1;
				}else if(a[j]==a[j+1])
				    x=1;
			}
		}
		if(x==0)
			cout<<"NO"<<endl;
			else cout<<"YES"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[5001],b[5002],x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
			b[a[j]]++;
			if(b[a[j]]>1)
				if(a[j]!=a[j-1]){
					cout<<"YES"<<endl;
					x=1;
					break;
				}
		}
		if(x==0)
			cout<<"NO"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[5001]={0},b[5001]={0},x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
			b[a[j]]++;
			if(b[a[j]]>1)
				if(a[j]!=a[j-1]){
					cout<<"YES"<<endl;
					x=1;
					break;
				}
		}
		if(x==0)
			cout<<"NO"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll t;
	cin>>t;
	for (ll i = 0; i < t; ++i)
	{
		ll n;
		cin>>n;
		ll a[5000],b[5000],x=0;
		for (ll j = 0; j < n; ++j)
		{
			cin>>a[j];
			b[a[j]]++;
			if(b[a[j]]>1 && j>0)
				if(a[j]!=a[j-1]){
					cout<<"YES"<<endl;
					x=1;
					break;
				}
		}
		if(x==0)
			cout<<"NO"<<endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define       IO 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ld long double
#define endl "\n"
#define lop(i, j, n)	for(int i = j; i<n; i++)
#define prl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x)	((1ll)*(x.size()))
#define srt(x) sort(x.begin(),x.end())
#define pri pair<int,int>
#define EPS 1e-9
#define vll vector<ll>
#define vii vector<int>
#define oo				1000000100
#define OO				10000000000100
#define PI atan(1.0)*4.0
#define sc(x) scanf("%d",&x)
ll n, m, q, T, k;
string s;
ll dp[10000],a,b,c;

int main() {
	IO;
	cin >> T;
	while (T--) {
		cin >> n;
		vll a(n);	ll f = 0;		map<ll, vll> pos;
		lop(i, 0, n) { cin >> a[i]; pos[a[i]].push_back(i); }
		if (n == 1) { cout << "YES\n"; continue; }
		lop(i, 0, n - 1) {
			lop(j, 0, sz(pos[a[i]])) {
				if (pos[a[i]][j] > i) { f = 1; break; }
			}
			if (f)break;
		}
		if (f)cout << "YES\n";
		else cout << "NO\n";
	}
	//cin >> n;
	//vll a(n), b(n), a_b(n);		multiset<ll> b_a;
	//lop(i, 0, n)cin >> a[i];
	//lop(i, 0, n)cin >> b[i];
	//lop(i, 0, n) { a_b[i] = a[i] - b[i];	b_a.insert(a_b[i] * -1); }
	//srt(b_a);	ll ans = 0, cnt = 0;
	//lop(i, 0, n) {
	//	auto pos = b_a.lower_bound(a_b[i]);
	//	/*if (a_b[i] >= 0) {
	//		cnt++;
	//	}*/
	//	b_a.erase(a_b[i] * -1);
	//
	//	if (a_b[i] == 0)ans++;
	//	/*}
	//	else {
	//		ans += pos
	//	}*/
	//}
	//cout << max(ans, 0LL) << endl;
	/*
	1
	30
	1 1 2 2 3 3 4 4 5 5 14 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 6 15 15
	*/
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define       IO 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ld long double
#define endl "\n"
#define lop(i, j, n)	for(int i = j; i<n; i++)
#define prl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x)	((1ll)*(x.size()))
#define srt(x) sort(x.begin(),x.end())
#define pri pair<int,int>
#define EPS 1e-9
#define vll vector<ll>
#define vii vector<int>
#define oo				1000000100
#define OO				10000000000100
#define PI atan(1.0)*4.0
#define sc(x) scanf("%d",&x)
ll n, m, q, T, k;
string s;
ll dp[10000],a,b,c;

int main() {
	IO;
	cin >> T;
	while (T--) {
		cin >> n;
		vll a(n), b(n);	ll cnt = 0, f = 0;		map<ll, vll> pos;		map<ll, bool>mp;
		lop(i, 0, n) { cin >> a[i]; pos[a[i]].push_back(i); }
		if (n == 1) { cout << "YES\n"; continue; }
		lop(i, 2, n) {
			if (a[i] == a[i - 2]) { f = 1; break; }
		}
		if (f)cout << "YES\n";
		else {
			ll l = 0, r = 1;
			while (l >= 0 && r < n)
			{
				if (a[l] == a[r]) {
					cnt += 2;
					l--, r++;
				}
				else l++, r++;
				if (cnt >= 3) { f = 1; break; }
			}
			if (f)cout << "YES\n";
			else {
				l = 1, r = 2,cnt=0;
				while (l >= 0 && r < n)
				{
					if (a[l] == a[r]) {
						cnt += 2;
						l--, r++;
					}
					else l++, r++;
					if (cnt >= 3) { f = 1; break; }
				}
				if (f)cout << "YES\n";
				else cout << "NO\n";
			}
		}
	}
	//cin >> n;
	//vll a(n), b(n), a_b(n);		multiset<ll> b_a;
	//lop(i, 0, n)cin >> a[i];
	//lop(i, 0, n)cin >> b[i];
	//lop(i, 0, n) { a_b[i] = a[i] - b[i];	b_a.insert(a_b[i] * -1); }
	//srt(b_a);	ll ans = 0, cnt = 0;
	//lop(i, 0, n) {
	//	auto pos = b_a.lower_bound(a_b[i]);
	//	/*if (a_b[i] >= 0) {
	//		cnt++;
	//	}*/
	//	b_a.erase(a_b[i] * -1);
	//
	//	if (a_b[i] == 0)ans++;
	//	/*}
	//	else {
	//		ans += pos
	//	}*/
	//}
	//cout << max(ans, 0LL) << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define       IO 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ld long double
#define endl "\n"
#define lop(i, j, n)	for(int i = j; i<n; i++)
#define prl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x)	((1ll)*(x.size()))
#define srt(x) sort(x.begin(),x.end())
#define pri pair<int,int>
#define EPS 1e-9
#define vll vector<ll>
#define vii vector<int>
#define oo				1000000100
#define OO				10000000000100
#define PI atan(1.0)*4.0
#define sc(x) scanf("%d",&x)
ll n, m, q, T, k;
string s;
ll dp[10000],a,b,c;

int main() {
	IO;
	cin >> T;
	while (T--) {
		cin >> n;
		vll a(n),b(n);	ll cnt = 0;
		lop(i, 0, n) { cin >> a[i]; }
		b = a;
		srt(b);
		lop(i, 0, n) {
			if (a[i] != b[i])cnt++;
		}
		if (cnt != 2)cout << "NO\n";
		else cout << "YES\n";
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define       IO 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ld long double
#define endl "\n"
#define lop(i, j, n)	for(int i = j; i<n; i++)
#define prl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x)	((1ll)*(x.size()))
#define srt(x) sort(x.begin(),x.end())
#define pri pair<int,int>
#define EPS 1e-9
#define vll vector<ll>
#define vii vector<int>
#define oo				1000000100
#define OO				10000000000100
#define PI atan(1.0)*4.0
#define sc(x) scanf("%d",&x)
ll n, m, q, T, k;
string s;
ll dp[10000],a,b,c;

int main() {
	IO;
	cin >> T;
	while (T--) {
		cin >> n;
		vll a(n);	ll f = 0;		map<ll, vll> pos;
		lop(i, 0, n) { cin >> a[i]; pos[a[i]].push_back(i); }
		if (n == 1) { cout << "YES\n"; continue; }
		lop(i, 0, n - 1) {
			lop(j, 0, sz(pos[a[i]])) {
				if (pos[a[i]][j] - i > 1) { f = 1; break; }
			}
			if (f)break;
		}
		if (f)cout << "YES\n";
		else cout << "NO\n";
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define       IO 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ld long double
#define endl "\n"
#define lop(i, j, n)	for(int i = j; i<n; i++)
#define prl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x)	((1ll)*(x.size()))
#define srt(x) sort(x.begin(),x.end())
#define pri pair<int,int>
#define EPS 1e-9
#define vll vector<ll>
#define vii vector<int>
#define oo				1000000100
#define OO				10000000000100
#define PI atan(1.0)*4.0
#define sc(x) scanf("%d",&x)
ll n, m, q, T, k;
string s;
ll dp[10000],a,b,c;

int main() {
	IO;
	cin >> T;
	while (T--) {
		cin >> n;
		vll a(n),b(n);	ll cnt = 0;
		lop(i, 0, n) { cin >> a[i]; }
		if (n == 1) { cout << "YES\n"; continue; }
		b = a;
		srt(b);
		lop(i, 0, n) {
			if (a[i] != b[i])cnt++;
		}
		if (cnt != 2)cout << "NO\n";
		else cout << "YES\n";
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define       IO 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ld long double
#define endl "\n"
#define lop(i, j, n)	for(int i = j; i<n; i++)
#define prl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x)	((1ll)*(x.size()))
#define srt(x) sort(x.begin(),x.end())
#define pri pair<int,int>
#define EPS 1e-9
#define vll vector<ll>
#define vii vector<int>
#define oo				1000000100
#define OO				10000000000100
#define PI atan(1.0)*4.0
#define sc(x) scanf("%d",&x)
ll n, m, q, T, k;
string s;
ll dp[10000],a,b,c;

int main() {
	IO;
	cin >> T;
	while (T--) {
		cin >> n;
		vll a(n), b(n);	ll cnt = 0, f = 0;		map<ll, vll> pos;		map<ll, bool>mp;
		lop(i, 0, n) { cin >> a[i]; pos[a[i]].push_back(i); }
		if (n == 1) { cout << "YES\n"; continue; }
		lop(i, 2, n) {
			if (a[i] == a[i - 2]) { f = 1; break; }
		}
		if (f)cout << "YES\n";
		else {
			ll l = 0, r = 1;
			while (l>=0&&r<n)
			{
				if (a[l] == a[r]) {
					cnt += 2;
					l--, r++;
				}
				else l++, r++;
				if (cnt >= 3) { f = 1; break; }
			}
			if (f)cout << "YES\n";
			else cout << "NO\n";
		}
	}
	/*cin >> T;
	while (T--)
	{
		cin >> s;	n = sz(s);
		ll ans = n

	}*/

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define       IO 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ld long double
#define endl "\n"
#define lop(i, j, n)	for(int i = j; i<n; i++)
#define prl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x)	((1ll)*(x.size()))
#define srt(x) sort(x.begin(),x.end())
#define pri pair<int,int>
#define EPS 1e-9
#define vll vector<ll>
#define vii vector<int>
#define oo				1000000100
#define OO				10000000000100
#define PI atan(1.0)*4.0
#define sc(x) scanf("%d",&x)
ll n, m, q, T, k;
string s;
ll dp[10000],a,b,c;

int main() {
	IO;
	cin >> T;
	while (T--) {
		cin >> n;
		vll a(n), b(n);	ll cnt = 0, f = 0;		map<ll, vll> pos;		map<ll, bool>mp;
		lop(i, 0, n) { cin >> a[i]; pos[a[i]].push_back(i); }
		if (n == 1) { cout << "YES\n"; continue; }
		lop(i, 0, n) {
			if (!mp[a[i]]) {
				b.push_back(a[i]);
				mp[a[i]] = 1;
			}
			else {
				if (binary_search(all(pos[a[i]]), i - 2)) { f = 1; break; }
				if (binary_search(all(pos[a[i]]), i - 1 - cnt)) { cnt += 2; }
				if (cnt >= 3) { f = 1; break; }
			}
		}
		if (f)cout << "YES\n";
		else cout << "NO\n";
	}
	/*cin >> T;
	while (T--)
	{
		cin >> s;	n = sz(s);
		ll ans = n

	}*/

	return 0;
}


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

bool palindrome(string str2)
{   bool yes;
    for(int i=0;i<str2.length()/2;i++)
    {
        if(str2[i]==str2[str2.length()-1-i])
        {  yes=true;  }
        else{ return false ;}
    }
    return yes;
}
void solve(string &str1)
{
   int i,j,c1=0;
   char ch[]=" ";
   str1.erase(remove(str1.begin(),str1.end(),ch[0]),str1.end());
   for(i=0;i<str1.length()-2;i++)
   {
      for(j=3;j<=str1.length();j++)
      {
          bool var=palindrome(str1.substr(i,j));
          if(var)
          { cout<<"YES\n"; c1=1;break;}
          else
          { c1=0;}
      }
      if(c1==1){ break;}
   }

   if(c1==0){cout<<"NO\n";}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    string str1;
    int t1,t2;
    cin>>t1;

    while(t1--)
    {
        cin>>t2;
        char ch=cin.get();
        getline(cin,str1);
        solve(str1);
    }
	return 0;
}


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

bool palindrome(vector<int> str2)
{   bool yes;
    for(int i=0;i<str2.size()/2;i++)
    {
        if(str2[i]==str2[str2.size()-1-i])
        {  yes=true;  }
        else{ return false ;}
    }
    return yes;
}
void solve(vector<int> &vec1)
{
   int i,j,c1=0;

   /*
     ----way to remove spaces from string object;----
   char ch[]=" ";
   str1.erase(remove(str1.begin(),str1.end(),ch[0]),str1.end());
   */

   /*
     ----way to check if string is palindrome----
     if( equal(str1.begin(), str1.begin() + str1.size()/2, str1.rbegin()) )
   */

   /*
     ----way to check if string is palindrome----
     string str3=str1.substr(i,j);
     if( equal(str3.begin(), str3.begin() + str3.size()/2, str3.rbegin()) )
   */

   for(i=0;i<vec1.size();i++)
   {
      for(j=3;j<=vec1.size()-i;j++)
      {   vector<int> vec2;
          vec2.assign(vec1.begin(),vec1.begin()+j);
          bool var=palindrome(vec2);
          if(var)
          { cout<<"YES\n"; c1=1;break;}
          else
          { c1=0;}
      }
      if(c1==1){ break;}
   }
   if(c1==0){cout<<"NO\n";}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    string str1;
    int t1,t2,i,x;
    cin>>t1;
    vector<int> vec1;
    while(t1--)
    {
        cin>>t2;
        char ch=cin.get();
        for(i=0;i<t2;i++)
        {        cin>>x;
                 vec1.push_back(x);
        }
        solve(vec1);
    }
	return 0;
}


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

bool palindrome(string str2)
{   bool yes;
    for(int i=0;i<str2.length()/2;i++)
    {
        if(str2[i]==str2[str2.length()-1-i])
        {  yes=true;  }
        else{ return false ;}
    }
    return yes;
}
void solve(string &str1)
{
   int i,j,c1=0;
   char ch[]=" ";
   str1.erase(remove(str1.begin(),str1.end(),ch[0]),str1.end());

   /*if( equal(str1.begin(), str1.begin() + str1.size()/2, str1.rbegin()) )
   */
   for(i=0;i<str1.length()-2;i++)
   {
      for(j=3;j<=str1.length()-i;j++)
      {
          //bool var=palindrome(str1.substr(i,j));
          string str3=str1.substr(i,j);
          //if(var)
          if( equal(str3.begin(), str3.begin() + str3.size()/2, str3.rbegin()) )
          { cout<<"YES\n"; c1=1;break;}
          else
          { c1=0;}
      }
      if(c1==1){ break;}
   }

   if(c1==0){cout<<"NO\n";}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    string str1;
    int t1,t2;
    cin>>t1;

    while(t1--)
    {
        cin>>t2;
        char ch=cin.get();
        getline(cin,str1);
        solve(str1);
    }
	return 0;
}


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

bool palindrome(string str2)
{   bool yes;
    for(int i=0;i<str2.length()/2;i++)
    {
        if(str2[i]==str2[str2.length()-1-i])
        {  yes=true;  }
        else{ return false ;}
    }
    return yes;
}
void solve(string &str1)
{
   int i,j,c1=0;
   char ch[]=" ";
   str1.erase(remove(str1.begin(),str1.end(),ch[0]),str1.end());

   /*if( equal(str1.begin(), str1.begin() + str1.size()/2, str1.rbegin()) )
   */
   for(i=0;i<str1.length();i++)
   {
      for(j=3;j<=str1.length()-i;j++)
      {
          //bool var=palindrome(str1.substr(i,j));
          string str3=str1.substr(i,j);
          //if(var)
          if( equal(str3.begin(), str3.begin() + str3.size()/2, str3.rbegin()) )
          { cout<<"YES\n"; c1=1;break;}
          else
          { c1=0;}
      }
      if(c1==1){ break;}
   }

   if(c1==0){cout<<"NO\n";}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    string str1;
    int t1,t2;
    cin>>t1;

    while(t1--)
    {
        cin>>t2;
        char ch=cin.get();
        getline(cin,str1);
        solve(str1);
    }
	return 0;
}


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

/*
bool palindrome(vector<int> str2)
{   bool yes;
    for(int i=0;i<str2.size()/2;i++)
    {
        if(str2[i]==str2[str2.size()-1-i])
        {  yes=true;  }
        else{ return false ;}
    }
    if( equal(str2.begin(), str2.begin() + str2.size()/2, str2.rbegin()) )
    {
    return true;}
    else{ return false;}
    return yes;
}
*/
/*
vector<int> vec2;
          vec2.assign(vec1.begin()+i,vec1.begin()+j+1);
          for(int k=i;k<i+j;k++){ vec2.push_back(vec1[k]);}
          for(int k=0;k<vec2.size();k++){ cout<<vec2[k]<<" ";}cout<<"\n";
          bool var=palindrome(vec2);
*/
/*
     ----way to remove spaces from string object;----
     char ch[]=" ";
     str1.erase(remove(str1.begin(),str1.end(),ch[0]),str1.end());
*/

/*
     ----way to check if string is palindrome----
     if( equal(str1.begin(), str1.begin() + str1.size()/2, str1.rbegin()) )
*/

/*
     ----way to check if string is palindrome----
     string str3=str1.substr(i,j);
     if( equal(str3.begin(), str3.begin() + str3.size()/2, str3.rbegin()) )
*/

void solve(vector<int> &vec1)
{
   int i,j,c1=0;

   for(i=0;i<vec1.size()-2;i++)
   {  for(j=i+2;j<vec1.size();j++)
      {   if(vec1[i]==vec1[j])
          { cout<<"YES\n"; c1=1;break;}
          else
          { c1=0;}
      }
      if(c1==1){ break;}
   }
   if(c1==0){cout<<"NO\n";}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    string str1;
    int t1,t2,i,x;
    cin>>t1;
    vector<int> vec1;
    vec1.reserve(5100);
    //cout<<vec1.size()<<"\n";
    while(t1--)
    {
        cin>>t2;
        //char ch=cin.get();
        for(i=0;i<t2;i++)
        {        cin>>x;
                 vec1.push_back(x);
                 //vec1[i]=x;
        }
        //for(auto j=0;j<t2;j++){  cout<<vec1[j]<<" ";}
        //cout<<"\n";
        solve(vec1);
        vec1.erase(vec1.begin(),vec1.end());
    }
	return 0;
}


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

bool palindrome(vector<int> str2)
{   bool yes;
    for(int i=0;i<str2.size()/2;i++)
    {
        if(str2[i]==str2[str2.size()-1-i])
        {  yes=true;  }
        else{ return false ;}
    }
   /* if( equal(str2.begin(), str2.begin() + str2.size()/2, str2.rbegin()) )
    {
    return true;}
    else{ return false;}*/
    return yes;
}
void solve(vector<int> &vec1)
{
   int i,j,c1=0;

   /*
     ----way to remove spaces from string object;----
   char ch[]=" ";
   str1.erase(remove(str1.begin(),str1.end(),ch[0]),str1.end());
   */

   /*
     ----way to check if string is palindrome----
     if( equal(str1.begin(), str1.begin() + str1.size()/2, str1.rbegin()) )
   */

   /*
     ----way to check if string is palindrome----
     string str3=str1.substr(i,j);
     if( equal(str3.begin(), str3.begin() + str3.size()/2, str3.rbegin()) )
   */

   for(i=0;i<vec1.size()-2;i++)
   {   //j is size of substring
      for(j=3;j<=vec1.size()-i;j++)
      {   vector<int> vec2;
          //vec2.assign(vec1.begin()+i,vec1.begin()+j+1);
          for(int k=i;k<i+j;k++){ vec2.push_back(vec1[k]);}
          //for(int k=0;k<vec2.size();k++){ cout<<vec2[k]<<" ";}cout<<"\n";
          bool var=palindrome(vec2);
          if(var)
          { cout<<"YES\n"; c1=1;break;}
          else
          { c1=0;}
      }
      if(c1==1){ break;}
   }
   if(c1==0){cout<<"NO\n";}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    string str1;
    int t1,t2,i,x;
    cin>>t1;
    vector<int> vec1;
    while(t1--)
    {
        cin>>t2;
        //char ch=cin.get();
        for(i=0;i<t2;i++)
        {        cin>>x;
                 vec1.push_back(x);
        }
        //for(auto j=0;j<t2;j++){  cout<<vec1[j]<<" ";}
        //cout<<"\n";
        solve(vec1);
        vec1.erase(vec1.begin(),vec1.end());
    }
	return 0;
}


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

int main () {
  ios :: sync_with_stdio(false);
  int t;
  cin >> t;
  while(t--) {
    int n, done = 0;
    cin >> n;
    vector <int> a(n + 1, 0), b(n + 1, 0);
    for(int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      if(a[x] == 0) {
        a[x] = i;
      } else {
        b[x] = i;
        if(b[x] - a[x] > 1) {
          cout << "YES" << endl;
          done = 1;
          break;
        }
      }
    }
    if(!done) {
      cout << "NO" << endl;
    }
  }

  return 0;
}


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

int main () {
  ios :: sync_with_stdio(false);
  int t;
  cin >> t;
  while(t--) {
    int n, done = 0;
    cin >> n;
    int a[5001] = {0}, b[5001] = {0};
    for(int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      if(a[x] == 0) {
        a[x] = i;
        b[x] = i;
        continue;
      }
      a[x] = min(i, a[x]);
      b[x] = max(i, b[x]);
      if(b[x] - a[x] > 1) {
        cout << "YES" << endl;
        done = 1;
        break;
      }
    }
    if(!done) {
      cout << "NO" << endl;
    }
  }

  return 0;
}


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

int main () {
  ios :: sync_with_stdio(false);
  int t;
  cin >> t;
  while(t--) {
    int n, done = 0;
    cin >> n;
    vector <int> a(5001, 0), b(5001, 0);
    for(int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      if(a[x] == 0) {
        a[x] = i;
      } else {
        b[x] = i;
        if(b[x] - a[x] > 1) {
          cout << "YES" << endl;
          done = 1;
          break;
        }
      }
    }
    if(!done) {
      cout << "NO" << endl;
    }
  }

  return 0;
}


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

int main () {
  ios :: sync_with_stdio(false);
  int t;
  cin >> t;
  while(t--) {
    int n, done = 0;
    cin >> n;
    int a[n + 1] = {0}, b[n + 1] = {0};
    for(int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      if(a[x] == 0) {
        a[x] = i;
        b[x] = i;
        continue;
      }
      a[x] = min(i, a[x]);
      b[x] = max(i, b[x]);
      if(b[x] - a[x] > 1) {
        cout << "YES" << endl;
        done = 1;
        break;
      }
    }
    if(!done) {
      cout << "NO" << endl;
    }
  }

  return 0;
}


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

int main () {
  ios :: sync_with_stdio(false);
  int t;
  cin >> t;
  while(t--) {
    int n, done = 0;
    cin >> n;
    vector <int> a(n + 1, 10000), b(n + 1, -10000);
    for(int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      a[x] = min(i, a[x]);
      b[x] = max(i, b[x]);
      if(b[x] - a[x] > 1) {
        cout << "YES" << endl;
        done = 1;
        break;
      }
    }
    if(!done) {
      cout << "NO" << endl;
    }
  }

  return 0;
}


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

int main () {
  ios :: sync_with_stdio(false);
  int t;
  cin >> t;
  while(t--) {
    int n, done = 0;
    cin >> n;
    int a[n + 1] = {0}, b[n + 1] = {0};
    for(int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      if(a[x] == 0) {
        a[x] = i;
      } else {
        b[x] = i;
        if(b[x] - a[x] > 1) {
          cout << "YES" << endl;
          done = 1;
          break;
        }
      }
    }
    if(!done) {
      cout << "NO" << endl;
    }
  }

  return 0;
}


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

int main () {
  ios :: sync_with_stdio(false);
  int t;
  cin >> t;
  while(t--) {
    int n, done = 0;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    for(int i = 0; i < n; i++) {
      for(int j = i + 2; j < n; j++) {
        if(arr[i] == arr[j]) {
          done = 1;
        }
      }
    }
    done ? cout << "YES" << endl : cout << "NO" << endl;
  }

  return 0;
}


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

int main () {
  ios :: sync_with_stdio(false);
  int t;
  cin >> t;
  while(t--) {
    int n, done = 0;
    cin >> n;
    int a[n + 1], b[n + 1];
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    for(int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      if(a[x] == 0) {
        a[x] = i;
      } else {
        b[x] = i;
        if(b[x] - a[x] > 1) {
          cout << "YES" << endl;
          done = 1;
          break;
        }
      }
    }
    if(!done) {
      cout << "NO" << endl;
    }
  }

  return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		vector<int> a(n);
		bool ok = false;
		rep(i, n) cin >> a[i];
		rep2(i, 1, n - 1) {
			if ((a[i - 1] == a[i + 1]) || (i >= 2 && a[i] == a[i - 1] && a[i + 1] == a[i - 2])) {
				cout << "YES" << endl;
				ok = true;
				break;
			}
		}
		if (!ok) cout << "NO" << endl;
	}
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		vector<int> a(n);
		bool ok = false;
		rep(i, n) cin >> a[i];
		rep2(i, 1, n - 1) {
			if ((a[i] == a[i - 1]) || (a[i] == a[i + 1]) ||(a[i - 1] == a[i + 1])) {
				cout << "YES" << endl;
				ok = true;
				break;
			}
		}
		if (!ok) cout << "NO" << endl;
	}
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

bool	check_palindrome(vector<int> arr, int size) {
	for (int i = 0; i <= size / 2; i++) {
		if (arr[i] != arr[size - i - 1])
			return false;
	}
	return true;
}

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;
	while (t--) {
		int n;
		bool ans = false;
		cin >> n;
		vector<int> v(n);
		rep(i, n) cin >> v[i];
		for (int mask = 0; mask < (1 << n); mask++) {
			bitset<5001> bs(mask);
			vector<int> sub;
			rep(i, n) {
				if (bs.test(i)) {
					sub.push_back(v[i]);
				}
			}
			if (sub.size() >= 3)
				ans = check_palindrome(sub, sub.size());
			if (ans) {
				puts("YES");
				break;
			}
		}
		if (!ans)
			puts("NO");
	}
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		vector<int> a(n);
		bool ok = false;
		rep(i, n) cin >> a[i];
		rep2(i, 1, n - 1) {
			if ((a[i - 1] == a[i + 1]) || (i + 2 < n && a[i - 1] == a[i + 2] && a[i] == a[i + 1])) {
				cout << "YES" << endl;
				ok = true;
				break;
			}
		}
		if (!ok) cout << "NO" << endl;
	}
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int		main(void)
{
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		vector<int> p(n);
		bool ok = false;
		rep(i, n) cin >> p[i];
		rep(i, n) {
			rep2(j, i + 2, n) {
				if (p[i] == p[j]) {
					ok = true;
				}
			}
		}
		if (ok) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int		main(void)
{
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		vector<int> p(n);
		rep(i, n) cin >> p[i];
		unordered_set<int> s;
		bool ok = false;
		rep2(i, 1, n) {
			if (s.count(p[i])) {
				ok = true;
				break;
			}
			s.insert(p[i - 1]);
		}
		if (ok) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

bool	check_palindrome(vector<int> &arr) {
	int size = arr.size();
	for (int i = 0; i <= size / 2; i++) {
		if (arr[i] != arr[size - i - 1])
			return false;
	}
	return true;
}

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;
	while (t--) {
		int n;
		bool ans = false;
		cin >> n;
		vector<int> v(n);
		rep(i, n) cin >> v[i];
		if (check_palindrome(v)) {
			puts("YES");
			continue;
		}
		for (int mask = 0; mask < (1 << n); mask++) {
			bitset<5001> bs(mask);
			vector<int> sub;
			rep(i, n) {
				if (bs.test(i)) {
					sub.push_back(v[i]);
				}
			}
			if (sub.size() >= 3)
				ans = check_palindrome(sub);
			if (ans) {
				puts("YES");
				break;
			}
		}
		if (!ans)
			puts("NO");
	}
}


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

#define pi                 3.1415926535897932384626433832795
#define ll                 long long
#define pb                 push_back
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define digits(n)          (floor(log10(n))+1;
#define max3(a,b,c)        max(a,max(b,c))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)

int a[200];

int main()
{

    int t,n,x,i,j;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
         int flag = 0;
        for(i=0;i<n;i++){
            cin>>a[i];
        }
        for(i=0;i<n;i++){
            for(j=i;j<n;j++){
                if(a[i]==a[j]){
                   if(abs(j-i)>1){
                    flag = 1;
                   }
                }
            }
        }

        if(flag==1)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;

    }

}


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

#define pi                 3.1415926535897932384626433832795
#define ll                 long long
#define pb                 push_back
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define digits(n)          (floor(log10(n))+1;
#define max3(a,b,c)        max(a,max(b,c))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)

int a[200005];

int main()
{
    fast_cin;
    int t,n,x,i;
    cin>>t;
    while(t--){
        cin>>n;
        int flag = 0,mx=0;
        memset(a,0,sizeof(a));
        for(i=1;i<=n;i++){
            cin>>x;
            if(a[x]){
                mx=max(mx,i-a[x]);
            }
            if(a[x]==0)a[x]=i;
            else if(i-a[x]!=1)a[x]=i;

        }
        if(mx>1)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }

}


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

#define pi                 3.1415926535897932384626433832795
#define ll                 long long
#define pb                 push_back
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define digits(n)          (floor(log10(n))+1;
#define max3(a,b,c)        max(a,max(b,c))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)

int a[200005];

int main()
{

    int t,n,x,i;
    cin>>t;
    while(t--){
        cin>>n;
        int flag = 0,mx=0;
        for(i=1;i<=n;i++)a[i]=0;
        for(i=1;i<=n;i++){
            cin>>x;
            if(a[x]){
                mx=max(mx,i-a[x]);
            }
            if(a[x]==0)a[x]=i;
            else if(i-a[x]!=1)a[x]=i;

        }
        if(mx>1)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }

}


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

#define pi                 3.1415926535897932384626433832795
#define ll                 long long
#define pb                 push_back
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define digits(n)          (floor(log10(n))+1;
#define max3(a,b,c)        max(a,max(b,c))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)

int a[200005];
int b[200005];

int main()
{

    int t,n,x,i,j;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int flag = 0;
        for(i=1;i<=n;i++){
            cin>>x;
           if(a[x]==0){a[x]=i;}
           else{
            if(i-a[x]>1){
                flag = 1;
                break;
            }
            a[x]=i;
           }

        }
        if(flag==1){
            cout<<"YES"<<endl;
        }
        else{cout<<"NO"<<endl;}

    }

}


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

#define pi                 3.1415926535897932384626433832795
#define ll                 long long
#define pb                 push_back
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define digits(n)          (floor(log10(n))+1;
#define max3(a,b,c)        max(a,max(b,c))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)

int a[50000];

int main()
{

    int t,n,x,i,j;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
         int flag = 0;
        for(i=0;i<n;i++){
            cin>>a[i];
        }
        for(i=0;i<n;i++){
            for(j=i;j<n;j++){
                if(a[i]==a[j]){
                   if(abs(j-i)>1){
                    flag = 1;
                   }
                }
            }
        }

        if(flag==1)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;

    }

}


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

#define pi                 3.1415926535897932384626433832795
#define ll                 long long
#define pb                 push_back
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define digits(n)          (floor(log10(n))+1;
#define max3(a,b,c)        max(a,max(b,c))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)

int a[200005];

int main()
{
    fast_cin
    int t,n,x,i;
    cin>>t;
    while(t--){
        cin>>n;
        int flag = 0,mx=0;
        memset(a,0,sizeof(a));
        for(i=1;i<=n;i++){
            cin>>x;
            if(a[x]){
                mx=max(mx,i-a[x]);
            }
            if(a[x]==0)a[x]=i;
            else if(i-a[x]!=1)a[x]=i;

        }
        if(mx>1)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }

}


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

#define pi                 3.1415926535897932384626433832795
#define ll                 long long
#define pb                 push_back
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define digits(n)          (floor(log10(n))+1;
#define max3(a,b,c)        max(a,max(b,c))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)

int a[200005];
int b[200005];

int main()
{

    int t,n,x,i,j;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int flag = 0;
        for(i=1;i<=n;i++){
            cin>>x;

            if(i-a[x]>1){
                flag = 1;
                break;
            }
            a[x]=i;
           }

        if(flag==1){
            cout<<"YES"<<endl;
        }
        else{cout<<"NO"<<endl;}

    }

}


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

#define pi                 3.1415926535897932384626433832795
#define ll                 long long
#define pb                 push_back
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define digits(n)          (floor(log10(n))+1;
#define max3(a,b,c)        max(a,max(b,c))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)

int a[200005];

int main()
{

    int t,n,x,i;
    cin>>t;
    while(t--){
        cin>>n;
        int flag = 0,mx=0;
        memset(a,0,sizeof(a));
        for(i=1;i<=n;i++){
            cin>>x;
            if(a[x]){
                mx=max(mx,i-a[x]);
            }
            if(a[x]==0)a[x]=i;
            else if(i-a[x]!=1)a[x]=i;

        }
        if(mx>1)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }

}


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

#define pi                 3.1415926535897932384626433832795
#define ll                 long long
#define pb                 push_back
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define digits(n)          (floor(log10(n))+1;
#define max3(a,b,c)        max(a,max(b,c))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)

int a[200005];
int b[200005];

int main()
{

    int t,n,x,i,j;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int flag = 0;
        for(i=1;i<=n;i++){
            cin>>x;
            if(a[x]==0)a[x]=i;
            else{
                if(i-a[x]>1)flag=1;
                a[x] = i;
            }
        }
        if(flag==1){
            cout<<"YES"<<endl;
        }
        else{cout<<"NO"<<endl;}

    }

}


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

#define pi                 3.1415926535897932384626433832795
#define ll                 long long
#define pb                 push_back
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define digits(n)          (floor(log10(n))+1;
#define max3(a,b,c)        max(a,max(b,c))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)

int a[200005];

int main()
{

    int t,n,x,i;
    cin>>t;
    while(t--){
        cin>>n;
        int flag = 0,mx=0;
        for(i=1;i<=n;i++)a[i]=0;
        for(i=1;i<=n;i++){
            cin>>x;
            if(a[x]){
                mx=max(mx,i-a[x]);
            }
            a[x]=i;

        }
        if(mx>1)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }

}