#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <locale>
#include <cstdio>

using namespace std;

// std::getline doesn't handle '\r' newlines properly.
void customGetline(ifstream& in, string& line)
{
    line.clear();
    
    while(in.good())
    {
        int c = in.get();
        if(c == '\r' || c == '\n' || c == EOF)
        {
            break;
        }
        line += (char)c;
    }
}

// strip leading and trailing spaces
string stripLine(const string& line)
{
    int a = INT_MAX, b = INT_MIN;
    for(int i = 0; i < (int)line.length(); ++i)
    {
        if(!isspace(line[i]))
        {
            a = min(a, i);
            b = max(b, i);
        }
    }
    
    if(b < 0)
    {
        // no non-whitespace chars found -- return empty string
        a = 0;
        b = -1;
    }
    
    return line.substr(a, b-a+1);
}

struct Token
{
    Token(const string& text, int line) : text(text), line(line) {}

    string text;
    int line;
};

class x3DMFParser
{

public:

    x3DMFParser()
        : lineNumber(0)
    {
        lines.push_back("");
    }

    void tokenizeLine(const string& line)
    {
        size_t position = 0;
        while(position < line.size())
        {
            // every time we get here, line[position] is the start of a token
           
           // compute the start and end position of the current token
            size_t start = position;
            while(position < line.size() && !isspace(line[position]))
            {
                position++;
            }
           
            // extract the token
            tokens.push_back(Token(line.substr(start, position-start), lineNumber));

            // skip past whitespace until we reach the next token
            while(position < line.size() && isspace(line[position]))
            {
                position++;
            }
        }   
    }
    
    void printTokens()
    {
        for(size_t i = 0; i < tokens.size(); ++i)
        {
            printf("%s\n", tokens[i].text.c_str());
        }
    }
    
    void inputLine(const string& line)
    {
        lineNumber++;
        
        lines.push_back(line);
        string stripped = stripLine(line); 
        
        // If (the line is empty, or is a comment)
        if(stripped.length() == 0 || stripped[0] == '#')
        {
            return;
        }

        tokenizeLine(stripped);
    }
    
private:

    int lineNumber;
    vector<Token> tokens;
    vector<string> lines;
};

int main(int argc, char **argv)
{
    if(argc != 2)
    {
        printf("Usage: %s [file]\n", argv[0]);
    }
    
    ifstream fin;
    fin.open(argv[1]);
    
    if(fin.fail())
    {
        printf("Input file failed to open.\n");
        return 0;
    }
   
    string line;
    x3DMFParser parser;

    do
    {
        customGetline(fin, line);
        parser.inputLine(line);
    } while(fin.good());
    
    parser.printTokens();
   
    fin.close();
}