import java.util.LinkedList;
import java.util.Scanner;
class GameOfRobots {
static LinkedList<Node> robots_sub_siquence = new LinkedList<Node>();
static int T;
static String s;
static boolean safe = true;
static Scanner mycan = new Scanner(System.in);
public static void main(String[] args) {
String s2 = "";
T = mycan.nextInt();
s2 = mycan.nextLine();
//System.out.println("T "+T);
//System.out.println("nextLine");
while (T != 0) {
//System.out.print("type string ");
s = mycan.nextLine();
//System.out.println(s);
//System.out.print("T "+"string "+s);
if (number_of_robots(s) <= 1) {
System.out.println("safe");
continue;
}else {
// CREATE SUB SEQUENCES
int start = next_robot(s, 0);
//System.out.println("start "+start);
while (start < s.length()) {
int j = next_robot(s, start+1);
if (j == -1) {
break;
}
//System.out.println("j "+j);
robots_sub_siquence.add(new Node(start, j));
start = j;
}
//display_sub_siquence(robots_sub_siquence);
}
// CHECKING COLLIDE OR NOT
for (int i = 0; i < robots_sub_siquence.size(); i++) {
Node tem = robots_sub_siquence.get(i);
int a = get_range(s, tem.getI());
int b = get_range(s, tem.getJ());
//System.out.println("a b : "+a+""+b);
int total_range = (int) a + b;
int distance = (int) (tem.getJ() - tem.getI());
//System.out.println("range : "+total_range);
//System.out.println("distance : "+distance);
if (total_range >= (distance)) {
System.out.println("unsafe");
safe = false;
break;
}
}
if (safe) {
System.out.println("safe");
}
T--;
robots_sub_siquence.clear();
safe = true;
s = null;
//System.out.println("T"+T);
}
}
/*
* 4
…
.2…
.2…2…
1.1.1.
*
*
*/
private static int get_range(String s2, long i) {
// TODO Auto-generated method stub
switch (s2.charAt((int) i)) {
case ‘0’:
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
default:
break;
}
return 0;
}
public static int next_robot(String s, int i) {
for (int j = i; j < s.length(); j++) {
if (s.charAt(j) != '.') {
return j;
}
}
return -1;
}
private static Node get_sub_sequence(int start, int end) {
// TODO Auto-generated method stub
return new Node(start, end);
}
private static int skip_dots(String s2, int j) {
// TODO Auto-generated method stub
for (int i = j; i < s2.length(); i++) {
if (s2.charAt(i) != '.' ) {
return i;
}
}
return -1;
}
@SuppressWarnings("unused")
private static void display_sub_siquence(
LinkedList<Node> robots_sub_siquence2) {
// TODO Auto-generated method stub
for (int i = 0; i < robots_sub_siquence2.size(); i++) {
System.out.print("i "+robots_sub_siquence2.get(i).getI());
System.out.print("j "+robots_sub_siquence2.get(i).getJ());
System.out.println();
}
}
private static int number_of_robots(String s2) {
// TODO Auto-generated method stub
int n = 0;
for (int i = 0; i < s2.length(); i++) {
if (s.charAt(i) != '.') {
n++;
}
}
return n;
}
}
class Node {
long i;
long j;
public Node(int i, int j) {
this.i = i;
this.j = j;
}
public Node(long l, long m) {
// TODO Auto-generated constructor stub
this.i = l;
this.j = m;
}
public void setI(int i) {
this.i = i;
}
public void setJ(int j) {
this.j = j;
}
public long getI() {
return i;
}
public long getJ() {
return j;
}
boolean isCollide(Node a){
return this.i == a.getI() && this.j == a.getJ();
}
public String toString() {
// TODO Auto-generated method stub
return "i "+i+" j "+j;
}
}