We need to analyze the problem: building a tower by stacking multiple standard six-sided dice (dice with faces 1-6 opposite sums to 7). Each die can be oriented arbitrarily. The dice are stacked vertically, presumably one on top of the other, with each die resting on the one below. The bottom die rests on a surface (perhaps also not counted). The faces that are visible are those not hidden by contact: top face of the topmost die; all four side faces (north, south, east, west) of all dice that are not hidden by adjacent dice? However, careful: In the example, they show a tower of two dice, and they count visible pips: top is 1, from the south 5 and 3, from the west 4 and 2, from the north 2 and 4 and from the east 3 and 5. That totals: top:1; south:5+3=8; west:4+2=6; north:2+4=6; east:3+5=8; sum=1+8+6+6+8=29. So they counted the side faces from each direction separately, summing pips on all dice visible from that direction. The faces that are hidden: the bottom face of the bottom die (touching ground) and the faces where dice touch each other: the top of the lower die is covered by the bottom of the upper die. Also, on the sides, if one die is directly above another, the side faces are all visible because there's no lateral covering; each die's side faces are visible regardless of stacking (unless the tower is leaning, but presumably it's a vertical stack, so the sides of each die are fully visible from the four cardinal directions). So the only hidden faces are: (1) the bottom face of the bottom die, (2) the top faces of all dice except the topmost, (3) the bottom faces of all dice except the bottommost? Actually bottom faces: only the bottommost die's bottom face is hidden (touching ground). For dice above, the bottom face is in contact with the top face of the die below, so that bottom face is hidden. So essentially for each die, either its top or bottom is hidden depending on position: for the topmost die, its top is visible, its bottom hidden (if there is a die below); for the bottommost, its bottom is hidden (ground) and its top is hidden if there is a die above? Wait careful: In a stack of n dice, we have die 1 (bottom), die 2, ..., die n (top). The bottom of die 1 touches ground -> hidden. The top of die 1 touches bottom of die 2 -> hidden. The bottom of die 2 touches top of die 1 -> hidden. The top of die 2 touches bottom of die 3 -> hidden. ... The bottom of die n touches top of die n-1 -> hidden. The top of die n is visible. So each die contributes exactly one visible face among its two vertical faces (top and bottom), except possibly if n=1? For a single die: bottom touches ground (hidden), top is visible. So exactly one visible vertical face per die: the top of the topmost die is visible, and all other top/bottom faces are hidden. Additionally, each die contributes four side faces (north, south, east, west) which are all visible (assuming the tower is straight). So the total visible pips = sum over all dice of (sum of pips on its four side faces) + (pip count on the top face of the topmost die). For each die, the sum of pips on its four side faces depends on its orientation. Since the die is a standard die with opposite faces summing to 7, the set of faces is {1,2,3,4,5,6} with pairs (1,6), (2,5), (3,4). When a die is placed, one face is down (touching the die below or ground), one face is up (could be top, but only topmost's up is visible), and four faces are side. The sum of the four side pips = total sum of all faces (21) minus the up and down pips. Since up+down = 7? Actually opposite faces sum to 7, but up and down are opposite? In a standard die, the faces are arranged so that opposite faces sum to 7. Usually, the 1 is opposite 6, 2 opposite 5, 3 opposite 4. In stacking, the die can be oriented arbitrarily, but the face that is down and the face that is up may not be opposite? Actually, in a cube, any orientation can have an arbitrary pair of faces as up and down, but they must be opposite faces because the cube's up and down directions are opposite. For a cube placed on a flat surface, the face that is down is the one in contact with the surface; the face that is up is the opposite face, because the cube's orientation has a vertical axis. However, can we have a die placed such that the up and down faces are not opposites? If we consider a cube resting on a table, the face in contact is flat on the table, and the opposite face is directly upward. So yes, up and down must be opposite faces. So the top and bottom faces of a die are always opposite, thus sum to 7. Therefore, for any die, the sum of its four side faces = 21 - (up + down) = 21 - 7 = 14. Interesting! So regardless of orientation, the total pips on the four side faces is always 14? Let's double-check: total sum of all faces = 1+2+3+4+5+6 = 21. Up+Down = 7 because they are opposite. So indeed 21-7=14. So each die contributes exactly 14 visible pips from its sides, regardless of orientation. However, careful: In the tower, the sides of each die are all visible. So each die (including the topmost and bottommost) contributes 14 from its sides? Yes, because side faces are always exposed. So for a tower of n dice, total side pips = 14 * n.
Now, the top of the tower: only the top face of the topmost die is visible. That top face can be any number from 1 to 6, but note that it must be opposite to the bottom face of that die (which is hidden as it contacts the die below). However, the top face value is not fixed; it can be any number from 1 to 6 depending on orientation, but it must be consistent with the die's orientation: given the down face (which is the face touching the die below), the top face is its opposite, so it is determined by the down face. But we can choose orientation arbitrarily, so we can set the top face to any desired value? Not exactly: Since the die's orientation is free, we can make the top face any number from 1 to 6, but we must also ensure that the bottom face (hidden) is the opposite number (7 - top). So yes, we can achieve any top face value from 1 to 6. Because we can orient the die such that the chosen number is on top, and the opposite number is on bottom. So the top face can be any of {1,2,3,4,5,6}.
Therefore, total visible pips for a tower of n dice = 14n + T, where T ∈ {1,2,3,4,5,6} is the top face value.
But wait, what about the bottom die's bottom face? That's hidden, already accounted. So formula seems correct.
Check example: n=2, 14*2=28, plus top face? In the example, total visible is 29, so top face would be 1. That matches: top face 1. And side sum? They computed sides sum: from south, west, north, east totals 5+3+4+2+2+4+3+5 = 28? Actually sum of sides = 5+3+4+2+2+4+3+5 = 28? Let's add: 5+3=8; +4=12; +2=14; +2=16; +4=20; +3=23; +5=28. Yes, plus top 1 = 29. So consistent.
Thus the problem reduces to: given an integer x (1 ≤ x ≤ 1e18), can we represent it as 14n + T where n >= 1? Actually n is number of dice. Is n allowed to be zero? No, Bob builds a tower by stacking multiple dice; presumably at least one die. So n ≥ 1. Also T ∈ {1,...,6}. So we ask: does there exist integer n ≥ 1 and T ∈ {1..6} such that x = 14n + T.
But wait, are there any additional constraints? Could the bottom face also contribute? In the example, they didn't count the bottom. So no.
But is there any possibility to get other values from a single die? For n=1, total = 14*1 + T = 14 + T, where T ∈ 1..6. So possible values: 15,16,17,18,19,20? Wait 14+1=15, 14+2=16, 14+3=17, 14+4=18, 14+5=19, 14+6=20. But in the third example of the problem, they say for 19, one can use a single die that has 5 on top. 14+5=19, yes. So that matches.
But are there any other possibilities? Could the orientation of the dice affect side pips sum differently if the up and down are not opposite? As argued, for a cube resting on a flat surface, the up and down faces must be opposite. But is it possible to place a die not oriented such that one face is flush on the lower die? Yes, stacking implies that each die sits squarely on the one below, so the contacting faces are parallel and flush. So the down face is the one in contact, which is flat; the top face is the opposite. So indeed up and down are opposite. Therefore 14 constant.
Thus the problem reduces to checking if x can be expressed as 14n + t, with n>=1, t ∈ [1,6].
But is there any lower bound? x≥1. For very small x like 1..14? Let's see: n=1 gives min 15. So numbers less than 15 are impossible? But x_i can be as low as 1. According to this, 1-14 would be NO. However, we should double-check: Could we have a tower with more than one die that yields smaller total? 14n + T, with n>=1, minimum when n=1, T=1 gives 15. So indeed values 1-14 are impossible. But is there any chance to get less than 15 by having a die placed such that some side faces are hidden? Wait: The problem statement: "He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each dice. Then he counts the number of visible pips on the faces of the dice." It didn't explicitly say the tower is vertical and the sides are all visible. However, from the example, they counted sides of both dice from each direction, so sides are visible. But could we intentionally orient dice such that some side faces are not visible because they are blocked by adjacent dice? Since dice are stacked directly on top of each other, their side faces are not overlapping; the upper die does not cover the sides of the lower die. So all side faces are always visible. So yes.
But wait: Could we consider that the tower might be built such that dice are rotated, but still sides are visible. So no.
Thus the set of possible visible pip counts is exactly {14n + t | n >= 1, t in {1,...,6}}.
But let's test the provided examples: 29 = 142+1 -> YES. 34 = 142+6? 142=28, +6=34 -> n=2, T=6 -> YES. 19 = 141+5 -> YES. 38 = 14*? 142=28+6=34; 143=42 >38; can't get 38 because 142+6=34, 143+1=43, so 38 not representable -> NO. That matches.
So the answer appears straightforward: for each x, check if x >= 15 and (x mod 14) is between 1 and 6 inclusive? Because 14n + t = x => n = floor(x/14) and remainder t = x mod 14. But careful: if x mod 14 = 0, then that would correspond to t=14, not allowed. So condition: x >= 15? Actually if x = 14, that would require n=1, t=0 not allowed. So yes, remainder must be 1..6. But also n must be at least 1, which is equivalent to x >= 15? Not exactly: if x=8? remainder 8 not in 1..6, fails anyway. So condition reduces to: Let r = x % 14. If r is between 1 and 6 inclusive, and x > 14? Wait what about x=14? r=0, fail. x=7? r=7, fail. So the smallest that can satisfy is x=15 (r=1). But what about x=1? r=1? 1 % 14 = 1, but 1 itself is less than 15; however if we set n=0? But n must be >=1, so we need x >= 14*1+1 = 15. So we must also enforce that the quotient (n = (x - r)/14) is at least 1. That means x - r >= 14, i.e., x >= 14 + r. Since r is at most 6, the minimal x satisfying that is x >= 14+1 = 15. So indeed we need to check that (x >= 15) implicitly. But we can explicitly check that (x >= 15) and (r ∈ 1..6). However, also note that if x is huge, that's fine.
But wait: Could there be a case where x is exactly 14? That would imply n=1, t=0 which is impossible. So NO.
Thus solution seems trivial: for each x, compute rem = x % 14; if rem >= 1 and rem <= 6 and x >= 15? But x >= 15 automatically ensures x > 14. But suppose x = 1? rem = 1, but x < 15. So we need to check both that rem is between 1 and 6, and that x > 14? Actually condition x >= 15 because n >= 1. So the correct condition: (x > 14) and (x % 14 ∈ [1,6]). But is x > 14 enough? For x=15, remainder 1, OK. For x=20, remainder 6, OK. For x=21, remainder 7, not OK. For x=28, remainder 0, not OK. So yes.
But wait, what about x=14? fails because remainder 0. So condition works with x>14 and remainder in 1..6.
However, consider x=14*0+1? Not allowed. So that's fine.
But is there any possibility to get x values less than 15 by using more than one die? For n=2, min is 28+1=29, larger. So no.
Thus answer: YES if x mod 14 ∈ {1,2,3,4,5,6} and x >= 15; else NO.
But let's test with some edge cases: x=15 -> YES (single die with top 1). x=20 -> YES (single die with top 6). x=21 -> NO. x=28 -> NO. x=29 -> YES. x=43 -> 43%14=1, x>=15? 43>14, YES => should be YES? Let's check: 14*3=42, +1=43 -> n=3, top=1, possible. So YES.
But wait, what about x=1? mod14=1 but x<15 => NO.
So far so good.
But is there any nuance about the dice stacking? Could the orientation of the lower dice affect the top face? The top face only depends on the topmost die orientation. The lower dice only contribute sides (14 each) and their top and bottom are hidden, so they don't affect T. So the only degree of freedom is n and T.
Thus problem reduces to checking membership in set S = {14n + t | n ∈ ℕ+, t ∈ {1,...,6}}.
Now note: The problem statement says: "Bob is playing with 6-sided dice. A net of such standard cube is shown below." The net shows standard die arrangement: typically 1 opposite 6, 2 opposite 5, 3 opposite 4. So yes.
But before finalizing, consider potential alternative interpretations: Could we stack dice in such a way that some side faces become hidden because dice are perfectly aligned and the upper die might cover part of the lower die's side? In a vertical stack, the dice are the same size; the upper die sits exactly on top of the lower die, so its projection is exactly the same footprint. The side faces of the lower die are below the upper die? Actually, if you place one cube directly on top of another, the upper cube's sides are directly above the lower cube's sides, but they do not occlude each other when viewing from the side? Consider viewing from the side: the lower cube's side face is still visible from an angle; but if you look from a horizontal direction, the upper cube's side face is in front of the lower cube's side face? Actually, imagine two cubes stacked. Looking from the north direction (horizontal), you see the north face of both cubes: the upper cube's north face is directly above the lower cube's north face. Both are visible, as they are in the same plane parallel to the viewing direction? Actually, they are coplanar? No, the north faces of both cubes are in the same vertical plane (assuming cubes are aligned). The lower cube's north face occupies a square from z=0 to z=1 (if cube side length 1). The upper cube's north face occupies from z=1 to z=2. So both faces are visible from a north view; there's no occlusion because they are not in front of each other; they are adjacent vertically. So both are fully visible. So all side faces are visible regardless of stack height.
Thus our reasoning stands.
Now about the problem constraints: t up to 1000, x up to 1e18. So we can compute modulo easily.
Thus the solution is simple: for each x, check if x > 14 and 1 <= x % 14 <= 6, print YES else NO.
But wait: Let's double-check the lower bound: the smallest possible is 15. But is there a scenario with n=0? No tower. So it's correct.
But are there any other possible values? Could we consider that the top face might also be hidden if we stack something on top? No, that's the topmost.
Could we consider that the bottom die's bottom face might be visible if the tower is placed on a transparent surface? The problem says: "The one at the bottom and the two sixes by which the dice are touching are not visible, so they are not counted towards total." So bottom face not visible.
Thus all good.
Now, we should also consider if there is any chance to get values that are less than 15 by using a die placed on its side? But stacking multiple dice implies they are placed on top of each other, each resting on a face of the die below. Could we place a die not resting on a face but on an edge or vertex? That would be unstable and not typical tower. Usually tower means each die rests flat on the one below, using a face. So only faces.
Thus answer stands.
But there is a twist: I've seen similar problems (Codeforces problem "Dice Tower" maybe). Actually I recall a Codeforces problem: "A. Dice Tower" or something where the answer is if x >= 15 and x%14 between 1 and 6. Yes, I think it's exactly that problem. So solution is as above.
But wait, I've also seen a variation where the dice are allowed to be placed in a tower where each die is rotated 45 degrees? No.
Thus final answer: For each x, if (x % 14 >= 1 && x % 14 <= 6 && x > 14) then YES else NO.
But is there any scenario where x = 14? That would require top face 0, not allowed.
Now, test with given examples: 29%14=1, >14 -> YES; 34%14=6, >14 -> YES; 19%14=5, >14 -> YES; 38%14=10? 14*2=28, 38-28=10, not in 1..6 -> NO. Good.
Thus we can output accordingly.
But wait, let's verify with another value: x=15: YES; x=20: YES; x=21: NO; x=22: 22%14=8 -> NO; x=23:9->NO; x=24:10->NO; x=25:11->NO; x=26:12->NO; x=27:13->NO; x=28:0->NO; x=29:1->YES; So pattern: every 14 numbers, there is a block of 6 possible numbers? Yes, from 15 to 20 inclusive (6 numbers) are possible. Then 21-27 (7 numbers) not possible? Actually 21-27 (7 numbers) none? 28 not possible; 29-34 possible (6 numbers); etc. So indeed for n>=2, the possible numbers are 14n+1 to 14n+6 inclusive, which is six numbers per block starting from n=1 (15-20). So it's consistent.
But is there any possibility to get numbers like 0? No.
Thus solution is simple.
But the problem might have additional nuance: Are we required to use at least one die? Yes. So condition as above.
Now we need to produce code accordingly.
However, we must be careful about large x up to 1e18: modulus works fine.
Thus implement:
Read t, then loop over x_i:
if x < 15: print NO
else:
r = x % 14
if 1 <= r <= 6: print YES else NO
That's it.
But let's test some edge cases: x=1e18. Compute r = 1e18 mod 14. That's okay but we can just do it. It may be high but Python handles big integers.
Now, why do we have to consider n>=1? Because x=0? Not given but anyway.
Thus final answer.
Wait, maybe there is also the possibility of using zero dice? Not allowed.
So answer stands.
But before concluding, I should re-read the problem statement carefully to ensure no hidden detail:
"Bob is playing with 6-sided dice. A net of such standard cube is shown below.
He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each dice. Then he counts the number of visible pips on the faces of the dice.
For example, the number of visible pips on the tower below is 29 — the number visible on the top is 1, from the south 5 and 3, from the west 4 and 2, from the north 2 and 4 and from the east 3 and 5.
The one at the bottom and the two sixes by which the dice are touching are not visible, so they are not counted towards total.
Bob also has t favourite integers x_i, and for every such integer his goal is to build such a tower that the number of visible pips is exactly x_i. For each of Bob's favourite integers determine whether it is possible to build a tower that has exactly that many visible pips."
So the description matches our interpretation.
However, one nuance: The example mentions "the two sixes by which the dice are touching are not visible". In the tower of two dice, the bottom die's top face is a 6? And the top die's bottom face is a 6? Actually they said "two sixes by which the dice are touching". This implies that the faces that are in contact are both sixes, i.e., the bottom die's top is 6 and the top die's bottom is 6. That's consistent with the fact that opposite faces sum to 7: If top of bottom die is 6, then its bottom is 1 (since opposite). But they didn't mention that. In the example, they counted sides: from south 5 and 3; west 4 and 2; north 2 and 4; east 3 and 5. This suggests that the bottom die has side faces: maybe the orientation is such that its south face is 5, west 4, north 2, east 3. The top die has sides: south 3, west 2, north 4, east 5. And the top die's top is 1. So the bottom die's top (touching the top die's bottom) is 6 (since 1 opposite 6? Actually top die's top is 1, so its bottom is 6. So the contacting faces are both 6. So the bottom die's top is 6. That means the bottom die has up=6, down=? Its down is on ground, hidden. So down must be opposite 6, i.e., 1. So the bottom die's bottom is 1. So it's consistent.
Thus the example further confirms that the side sum for each die is 14: bottom die sides: 5+4+2+3=14? Actually 5+4+2+3 =14, yes. Top die sides: 3+2+4+5 =14. Top face 1. So total 29.
Thus our derived formula is correct.
Now, could there be a scenario where the tower has only one die, and we might consider that the die's bottom is hidden, top visible, and sides visible. So side sum =14, plus top (1-6) yields numbers 15-20. That's fine.
Thus solution is simple.
Nevertheless, I've seen some solutions for this problem (Codeforces 225A?) that check if x >= 15 and x % 14 between 1 and 6. That is indeed the answer.
But wait, there is another known Codeforces problem: "Dice Tower" (Codeforces Round #386 (Div. 2), problem A?). In that problem, they asked for whether a given integer can be the sum of visible pips on a dice tower. Many participants solved it by checking if x > 14 and x % 14 <= 6 and x % 14 != 0. Actually I recall some nuance: The answer might also allow x = 21? But in that problem, the dice were stacked such that only three faces are visible? No, that's different.
Better to verify: There is a known problem: "Dice Tower" from Codeforces Round #353 (Div. 2) maybe? I recall problem 225A "Tower of Hanoi"? Not sure.
I should verify with more values: The problem states that the tower can have multiple dice, but the example uses two dice. So it's consistent.
Now, consider x=14*0+8? Not possible.
Thus algorithm is O(t).
Now, we just need to write the solution.
But before finalizing, consider if there is any possibility of achieving numbers less than 15 by using a die placed on its side? The phrase "tower" suggests vertical stacking, so all dice are oriented with a face down. So no.
Thus final answer: for each x, print YES if x > 14 and 1 <= x % 14 <= 6 else NO.
But wait, what about x=0? Not in range.
Alright.
Now, produce code accordingly.
But hold on: The problem constraints: t up to 1000, x up to 1e18, so 64-bit integers, we need to use long long in C++ or Python's int.
Now, one more nuance: The dice are standard with opposite faces sum to 7. But are we absolutely certain that the sum of the four side faces is always 14? Yes, because up+down = 7. However, is it always true that up and down are opposite? For a cube resting on a face, the face opposite the resting face is pointing straight up. So yes. In stacking, each die sits on a face of the die below, so its down face is flush with the top face of the die below. The die's orientation can be rotated about the vertical axis, but the down and up faces remain opposite. So always opposite.
Thus the side sum is constant.
Thus answer stands.
Now, we can output.
But before final answer, I should check the sample: Input 4 numbers: 29 34 19 38. Our conditions: 29>14, 29%14=1 => YES. 34>14, 34%14=6 => YES. 19>14, 19%14=5 => YES. 38>14, 38%14=10 => NO. matches.
Thus solution is correct.
Now, implement:
In Python:
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data: return
t = int(data[0])
out = []
for i in range(1, t+1):
x = int(data[i])
if x < 15:
out.append("NO")
else:
r = x % 14
if 1 <= r <= 6:
out.append("YES")
else:
out.append("NO")
sys.stdout.write("\n".join(out))
That's it.
But we could also combine condition: (x > 14) and (1 <= x%14 <= 6). Good.
Now, I should consider if there is any trick: Could x be exactly 14? Then x>14 is false, so NO. Good.
Now, potential overflow: not in Python.
Thus final answer.
But the problem statement says: "The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of favourite integers of Bob." Then second line contains t integers x_i. So reading is straightforward.
Thus final.
Now, produce final output. ```python
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
t = int(data[0])
out = []
for i in range(1, t + 1):
x = int(data[i])
# Condition: at least one die (x >= 15) and remainder 1..6
if x > 14 and 1 <= (x % 14) <= 6:
out.append("YES")
else:
out.append("NO")
sys.stdout.write("\n".join(out))
if name == "main":
solve()