Problem: Your task is the exact same as for the easy version. But this time, the marmots subtract the village's population P from their random number before responding to Heidi's request.

Also, there are now villages with as few as a single inhabitant, meaning that <image>.

Can you help Heidi find out whether a village follows a Poisson or a uniform distribution?

Input

Same as for the easy and medium versions. But remember that now 1 ≤ P ≤ 1000 and that the marmots may provide positive as well as negative integers.

Output

Output one line per village, in the same order as provided in the input. The village's line shall state poisson if the village's distribution is of the Poisson type, and uniform if the answers came from a uniform distribution.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int a[250];
double log_fact[5001], inf;
inline double get_log_fact(int k) { return log_fact[min(k, 5000)]; }
double get_poisson_prob(int p) {
  double sum = 0;
  for (int i = 0; i < 250; ++i) {
    int k = a[i] + p;
    if (k < 0) {
      return -inf;
    }
    double single_prob = log(p) * k - p - get_log_fact(k);
    sum += single_prob;
  }
  return sum;
}
double get_uniform_prob(int p) {
  for (int i = 0; i < 250; ++i) {
    int k = a[i] + p;
    if (k < 0 || k > 2 * p) {
      return -inf;
    }
  }
  return -log(p * 2 + 1) * 250;
}
int main(void) {
  log_fact[0] = 0;
  inf = 1e100;
  for (int k = 1; k <= 5000; ++k) {
    log_fact[k] = log_fact[k - 1] + log(k);
    inf = inf * inf;
  }
  int cas;
  scanf("%d", &cas);
  while (cas--) {
    for (int i = 0; i < 250; ++i) {
      scanf("%d", a + i);
    }
    double prob = -inf;
    pair<int, bool> ans = pair<int, bool>(-1, false);
    for (int p = 1; p <= 1000; ++p) {
      double prob_poisson = get_poisson_prob(p);
      if (prob_poisson > prob) {
        prob = prob_poisson;
        ans = pair<int, bool>(p, false);
      }
      double prob_uniform = get_uniform_prob(p);
      if (prob_uniform > prob) {
        prob = prob_uniform;
        ans = pair<int, bool>(p, true);
      }
    }
    puts(ans.second ? "uniform" : "poisson");
  }
  return 0;
}