#ifndef String_HEADER
#define String_HEADER

/**
 * File    : String.h
 * Author  : Kazune Takahashi
 * Created : 7/9/2019, 9:00:03 PM
 * Powered by Visual Studio Code
 */

#include <stdexcept>
#include <cstring>

class String
{
public:
  String();
  String(const char *p);
  String(const String &);            // copy
  String &operator=(const String &); // copy 代入
  String(String &&);                 // move
  String &operator=(String &&);      // move 代入
  ~String()
  {
    if (short_max < sz)
    {
      delete[] ptr;
    }
  }

  char &operator[](int n) { return ptr[n]; }
  char operator[](int n) const { return ptr[n]; }
  char &at(int n)
  {
    check(n);
    return ptr[n];
  }
  char at(int n) const
  {
    check(n);
    return ptr[n];
  }

  String &operator+=(char c);

  char *c_str() { return ptr; }
  const char *c_str() const { return ptr; }

  int size() const { return sz; }
  int capacity() const { return (sz <= short_max) ? short_max : sz + space; }

private:
  static const int short_max = 15;
  int sz;
  char *ptr;
  union {
    int space;
    char ch[short_max + 1];
  };
  void check(int n) const
  {
    if (!(0 <= n && n < sz))
    {
      throw std::out_of_range("String::at()");
    }
  }
  void copy_from(const String &);
  void move_from(String &);
};

char *expand(const char *ptr, int n)
{
  char *p = new char[n];
  std::strcpy(p, ptr);
  return p;
}

#endif // String_HEADER


#include <iostream>
using std::istream;
using std::ostream;

void String::copy_from(const String &x)
{
  if (x.sz <= short_max)
  {
    std::memcpy(this, &x, sizeof(x));
    ptr = ch;
  }
  else
  {
    ptr = expand(x.ptr, x.sz + 1);
    sz = x.sz;
    space = 0;
  }
}

void String::move_from(String &x)
{
  if (x.sz <= short_max)
  {
    std::memcpy(this, &x, sizeof(x));
    ptr = ch;
  }
  else
  {
    ptr = x.ptr;
    sz = x.sz;
    space = x.space;
    x.ptr = x.ch;
    x.sz = 0;
    x.ch[0] = 0;
  }
}

String::String() : sz{0}, ptr{ch}
{
  ch[0] = 0;
}

String::String(const char *p) : sz(std::strlen(p)), ptr{(sz <= short_max) ? ch : new char[sz + 1]}, space{0}
{
  std::strcpy(ptr, p);
}

String::String(const String &x)
{
  copy_from(x);
}

String::String(String &&x)
{
  move_from(x);
}

String &String::operator=(const String &x)
{
  if (this == &x)
  {
    return *this;
  }
  if (short_max < sz)
  {
    delete[] ptr;
  }
  copy_from(x);
  return *this;
}

String &String::operator=(String &&x)
{
  if (this == &x)
  {
    return *this;
  }
  if (short_max < sz)
  {
    delete[] ptr;
  }
  move_from(x);
  return *this;
}

String &String::operator+=(char c)
{
  if (sz == short_max)
  {
    int n = sz * 2 + 2;
    ptr = expand(ptr, n);
    space = n - sz - 2;
  }
  else if (short_max < sz)
  {
    if (space == 0)
    {
      int n = sz * 2 + 2;
      char *p = expand(ptr, n);
      delete ptr;
      ptr = p;
      space = n - sz - 2;
    }
    else
    {
      --space;
    }
  }
  ptr[sz] = c;
  ptr[++sz] = 0;
  return *this;
}

ostream &operator<<(ostream &os, const String &s)
{
  return os << s.c_str();
}

istream &operator>>(istream &is, String &s)
{
  s = "";
  is >> std::ws;
  char ch{};
  while (is.get(ch) && !std::isspace(ch))
  {
    s += ch;
  }
  return is;
}

bool operator==(const String &a, const String &b)
{
  if (a.size() != b.size())
  {
    return false;
  }
  for (auto i = 0; i < a.size(); i++)
  {
    if (a[i] != b[i])
    {
      return false;
    }
  }
  return true;
}

bool operator!=(const String &a, const String &b)
{
  return !(a == b);
}

bool operator<(const String &a, const String &b)
{
  for (auto i = 0; i <= a.size(); i++)
  {
    if (a[i] < b[i])
    {
      return true;
    }
    else if (a[i] > b[i])
    {
      return false;
    }
  }
  return false;
}

bool operator<=(const String &a, const String &b)
{
  return a < b || a == b;
}

bool operator>(const String &a, const String &b)
{
  return !(a <= b);
}

bool operator>=(const String &a, const String &b)
{
  return a > b || a == b;
}

char *begin(String &x)
{
  return x.c_str();
}

char *end(String &x)
{
  return x.c_str() + x.size();
}

const char *begin(const String &x)
{
  return x.c_str();
}

const char *end(const String &x)
{
  return x.c_str() + x.size();
}

String &operator+=(String &a, const String &b)
{
  for (auto x : b)
  {
    a += x;
  }
  return a;
}

String operator+(const String &a, const String &b)
{
  String ans{a};
  ans += b;
  return ans;
}

#include <tuple>
#include <vector>
#include <algorithm>

using restaurant = std::tuple<String, int, int>;

int main()
{
  int N;
  std::cin >> N;
  std::vector<restaurant> V;
  for (auto i = 0; i < N; i++)
  {
    String S;
    int P;
    std::cin >> S >> P;
    V.push_back(restaurant(S, -P, i + 1));
  }
  std::sort(V.begin(), V.end());
  for (auto x : V)
  {
    std::cout << std::get<2>(x) << std::endl;
  }
}

Measured memory_bytes: 256