let inputString;

process.stdin.on('data', (input) => { inputString += input; });

process.stdin.on('end', () => {
  proc(inputString);
});

const proc = (input) => {
  const arr = toMappedArr(input);
  const origin = collectWithNum(arr);

  quickSort(arr, 0, arr.length - 1);

  const sorted = collectWithNum(arr);
  const stable = Object
    .keys(origin)
    .every((key) => {
      return origin[key]
        .every((mark, index) => {
          return mark === sorted[key][index];
        });
    });
  console.log(stable ? 'Stable' : 'Not stable');
  console.log(arr.map((obj) => `${obj.mark} ${obj.num}`).join('\n'));
};

const toMappedArr = (input) => {
  const arr = input
    .replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));
  arr.shift();
  return arr
    .map((str) => {
      const arr = str.split(' ');
      return {
        mark: arr[0],
        num: Number(arr[1]),
      };
    });
};

const collectWithNum = (arr) => {
  const obj = {};
  arr.forEach((value) => {
    if (!!obj[value.num]) {
      obj[value.num].push(value.mark);
    } else {
      obj[value.num] = [value.mark];
    }
  });
  return obj;
};

const quickSort = (arr, p, r) => {
  if (p < r) {
    const q = partition(arr, p, r);
    quickSort(arr, p, q - 1);
    quickSort(arr, q + 1, r);
  }
};

const partition = (arr, p, r) => {
  const x = arr[r].num;
  let i = p - 1;
  for (let j=p; j<r; j++) {
    if (arr[j].num <= x) {
      i = i + 1;
      const needToBeInLeft = arr[j];
      const needToBeInRight = arr[i];
      arr[i] = needToBeInLeft;
      arr[j] = needToBeInRight;
    }
  }
  const needToBeInRight = arr[r];
  const needToBeInLeft = arr[i + 1];
  arr[i+1] = needToBeInRight;
  arr[r] = needToBeInLeft;
  return i + 1;
};
