// Arup Guha
// 8/25/2021
// A program that determines the first index at which one string is a substring of another string.
// Written to illustrate the assignment protocol for COP 3502

#include <stdio.h>
#include <string.h>

#define MAX 99

int substring_at(char str[], char sub[]);

int main(void) {

  // Read in the number of cases. Most assignments will only have this outside of the case loop.
  int numCases;
  scanf("%d", &numCases);

  // Case loop.
  for (int loop=0; loop<numCases; loop++) {

    // Read in the two strings. Variable declarations needed to read in case information should go here.
    char str[MAX+1], sub[MAX+1];
    scanf("%s%s", str, sub);

    // Ta da! For all assignments print the output for a single case AS SOON AS you complete calculating the answer.
    printf("%d\n", substring_at(str, sub));
  }

  // Only thing that should be here.
  return 0;
}

// This function returns the first index at which sub appears in str. If sub doesn't appear in str, -1 is returned.
int substring_at(char str[], char sub[]) {

  // Store lengths.
  int bigL = strlen(str);
  int smallL = strlen(sub);

  // i represents all possible starting positions of the substring.
  for (int i=0; i<=bigL-smallL; i++) {

    // So far it's okay.
    int ok = 1;

    // Check each character for a match.
    for (int j=0; j<smallL; j++) {
      if (sub[j] != str[i+j]) {
        ok = 0;
	break;
      }
    }

    // It matches, return it.
    if (ok) return i;
  }

  // If we get here, there was no match.
  return -1;
}
