Problem: 2049B - pspspsps
Language: java

Solution 1 (runtime: 218 ms):
import java.util.*;
import java.io.*;

public class Main {
	static InputStream inputStream;
	static OutputStream outputStream;
	static InputReader in;
	static PrintWriter out;
	static int MULTIPLE_TESTCASES = 1;
	static String PROB_NAME = "";

	///////////////////////////////////////
	// solution
	///////////////////////////////////////
	static class Solution {

		public void solve(int tc) throws IOException {
			int n = in.ni();
			char[] s = in.ns().toCharArray();
			int sc = 0;
			int pc = 0;
			int dc = 0;

			if (s[0] == '.')
				s[0] = 's';
			if (s[n - 1] == '.')
				s[n - 1] = 'p';
			for (int i = 0; i < n; ++i) {
				if (s[i] == 'p')
					++pc;
				else if (s[i] == 's')
					++sc;
				else
					++dc;
			}
			if (sc == 0 || pc == 0) {
				out.println("YES");
				return;
			}
			if (s[0] == 's' && pc + dc == n - 1) {
				out.println("YES");
				return;
			}
			if (s[n - 1] == 'p' && sc + dc == n - 1) {
				out.println("YES");
				return;
			}
			out.println("NO");
		}
	}

	private static void precompute() {

	}

	///////////////////////////////////////
	// template
	///////////////////////////////////////
	public static void main(String[] args) throws IOException {
		inputStream = System.in;
		outputStream = System.out;
		if (PROB_NAME != "") {
			inputStream = new FileInputStream(new File(PROB_NAME + ".in"));
			outputStream = new FileOutputStream(new File(PROB_NAME + ".out"));
		}
		in = new InputReader(inputStream);
		out = new PrintWriter(outputStream);
		int tc = 1;
		if (MULTIPLE_TESTCASES > 0)
			tc = in.ni();
		precompute();
		Solution sol = new Solution();
		for (int i = 1; i <= tc; ++i) {
			sol.solve(i);
		}
		in.close();
		out.close();
	}

	static class InputReader {
		BufferedReader reader;
		StringTokenizer st;

		public InputReader(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
			st = null;
		}

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

		public Long nl() throws IOException {
			return Long.parseLong(ns());
		}

		public Integer ni() throws IOException {
			return Integer.parseInt(ns());
		}

		public int[] nia(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; ++i) {
				a[i] = ni();
			}
			return a;
		}

		public long[] nla(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; ++i) {
				a[i] = nl();
			}
			return a;
		}

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


Solution 2 (runtime: 328 ms):
import java.util.*;

public class psp {
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        int tc = sc.nextInt();
        for(int i = 0; i < tc; i++){
            int n = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            String[] ps = new String[n];
            for(int j = 0; j < n; j++){
                ps[j] = s.substring(j, j+1);
            }
            //set up

            //test1
            String r = "yes";
            boolean pe = false;
            for(int j = 0; j < n; j++){
                if(ps[j].equals("p")){
                    pe = true;
                }
                if(pe && ps[j].equals("s")){
                    r = "no";
                    break;
                }
            }
            boolean se = false;
            for(int j = 1; j < n-1; j++){
                if(ps[j].equals("s")){
                    se = true;
                }
                if(se && ps[j].equals("p")){
                    r = "no";
                    break;
                }
            }
            System.out.println(r);
        }
    }
    
}