class Solution {
public String solution(int n, int t, int m, int p) {
String numbers = "";
String result = "";
for (int i = 0; i <= t * m; i++) {
numbers += Integer.toString(i, n);
}
for (int i = 0; i < t * m; i += m) {
char word = numbers.charAt(i + p - 1);
if (Character.isAlphabetic(word)) word = Character.toUpperCase(word);
result += word;
}
return result;
}
}