#include<stdio.h>
int nextNumberMultipleOf3(int num) {
  int rem = num %3;
  return num + (3 - rem);
}

int nextNumberMultipleOf5(int num) {
  int rem = num %5;
  return num + (5 - rem);
}

int main(){
  int t;
  unsigned long num, sum, i;

  scanf("%d", &t);
  while(t-->0) {
    sum = 0;
    scanf("%d", &num);

    for (i = 3 ; i< num ;) {
      sum += i;
      
      int next3 = nextNumberMultipleOf3(i);
      int next5 = nextNumberMultipleOf5(i);

      if (next3 < next5) {
        i = next3;
      } else {
        i = next5;
      }
    }
    printf("%lu\n", sum);
  }
  return 0;
}
