why is my output delayed by one iteration?
#include <stdio.h>
#include <stdlib.h>

int main() {

    char phone[11];
    scanf("%s\n", phone);
    
    int num;
    scanf("%d\n", &num);
    while (scanf(" %d\n", &num) == 1) {
    	if (num == -1) {
    	    printf("%s\n", phone);
	} else if (0 <= num && num <= 9) {
	    printf("%c\n", phone[num]);
	} else {
	    printf("ERROR\n");
	}
    }
    return 0;
}