import java.math.BigInteger;
import java.io.*;
import java.util.*;

public class LatAndLongGetter
{
  public static String ipHops[];
  public static String locations[];
  public static String blocks[];
  public static String temp[];
  public static String ipNums[];
  
  public static void main(String[] args) throws Exception
  {
    ipHops = loadStrings("outputIPs.txt");
    locations = loadStrings("GeoLiteCity-Location.csv");
    blocks = loadStrings("GeoLiteCity-Blocks.csv");
    ipNums = loadStrings(args[0]); //given filename for the outputIPNums
    PrintWriter out;// = new PrintWriter("outputCoordinates.txt");
    if(args.length<=1)//if user does not specify an output filename
    {
      out = new PrintWriter("outputCoordinates.txt");
    }
    else
    {
      out = new PrintWriter(args[1]); //can allow user to choose output name
    }
    
    for(int i = 0; i < ipNums.length; i++)
    {
      BigInteger ipNumber = new BigInteger(ipNums[i]);
      BigInteger locIDNum = getLocId(ipNumber);
      if(locIDNum.intValue()!=-1)
      {
        out.println(getLatitude(locIDNum) + "," + getLongitude(locIDNum));
      }
    }
    out.close();
  }
  
  
  public static BigInteger getLocId(BigInteger ipNum)
  {
    
    for(int i = 2; i < blocks.length; i++)
    {
      //temp = split(blocks[i], ","); //the processing command
      temp = blocks[i].split(",");
      if((ipNum.compareTo(new BigInteger(temp[0].substring(1,temp[0].length()-1)))>=0)&&(ipNum.compareTo(new BigInteger(temp[1].substring(1,temp[1].length()-1)))<=0))
      {
        return new BigInteger(temp[2].substring(1,temp[2].length()-1));
      }
    }
    return new BigInteger("-1");//if not found
  }
  
  
//Requires a locId from 1-locations.length
  public static double getLatitude(BigInteger locId)
  {
    //String[] locationSplit = split(locations[locId+1],",");
    String[] locationSplit = locations[locId.add(BigInteger.ONE).intValue()].split(",");
    String lat = locationSplit[5];
    return Double.parseDouble(lat); //converts lat string to double and returns
  }
  
  public static double getLongitude(BigInteger locId)
  {
    //String[] locationSplit = split(locations[locId+1],",");
    String[] locationSplit = locations[locId.add(BigInteger.ONE).intValue()].split(",");
    String lon = locationSplit[6];
    return Double.parseDouble(lon);//converts lon string to double and returns
  }
  
  public static String[] loadStrings(String filename) throws Exception
  {
    FileReader reader = new FileReader(filename);
    Scanner in = new Scanner(reader);
    int count = 0;
    while(in.hasNextLine())
    {
      in.nextLine();
      count++;
    }
    String[] temp = new String[count];
    int num = 0;
    FileReader reader2 = new FileReader(filename);
    Scanner in2 = new Scanner(reader2);
    while(in2.hasNextLine())
    {
      temp[num] = in2.nextLine();
      num++;
    }
    in.close();
    in2.close();
    return temp;
  }
}   
      
      