Calculation of the distance to the next space station
Here are a few tips:


Instead of getting each character, creating a new string from it, and then parse the string into a number, just get the character and convert the character code into the number.
Alternatively, parse the whole number once, then get the digits numerically using modulo.
There are only ten digits, so you can easily set up an array of precalculated cube values.
K is a double, but there are no floating point operations here. Use an int, or a long if needed.


Example:

int T = Convert.ToInt32(Console.ReadLine());
int[] cube = { 0, 1, 4, 9, 16, 25, 36, 49, 64, 81 };
for (int k = 0; k &lt; T; k++) {
  string[] split = Console.ReadLine().Split(' ');
  int N = Convert.ToInt32(split[0]);
  int Kst = Convert.ToInt32(split[1]);
  int K = 0;
  for (int i = 0; i &lt; N - 1; i++) {
    K = 0;
    while (Kst &gt; 0) {
      K += cube[Kst % 10];
      Kst /= 10;
    }
    Kst = K;
  }
  Console.WriteLine(K - Convert.ToInt32(split[2]));
}