#error "tsurai"

#include <cstdio>
#include <cstdint>
#include <cctype>
#include <cassert>
#include <algorithm>
#include <vector>
#include <map>

template <intmax_t X=9436884629, intmax_t MOD=1000000007>
class RollingHash {
  std::vector<intmax_t> hash_;
  intmax_t offset(size_t len) const {
    intmax_t res=1;
    for (intmax_t dbl=X%MOD; len; len>>=1) {
      if (len & 1)
        res = res*dbl % MOD;

      dbl = dbl*dbl % MOD;
    }

    return res;
  }

public:
  RollingHash(const std::string &s): hash_(s.length()+1) {
    for (size_t i=0; i<s.length(); ++i)
      hash_[i+1] = (hash_[i]*X+s[i]) % MOD;
  }

  intmax_t prefix(size_t i) const {
    // hash of prefix s[0..i-1] (inclusive)
    assert(0 < i);
    return hash_[i];
  }

  intmax_t substr(size_t i, size_t j) const {
    // hash of substring s[i..j-1] (inclusive)
    assert(i < j);
    intmax_t res=hash_[j];
    res = (res - offset(j-i)*hash_[i]) % MOD;
    if (res < 0) res += MOD;
    return res;
  }

  intmax_t hash() const {
    return hash_.back();
  }

  void debug() const {
    for (size_t i=0; i<hash_.size(); ++i)
      fprintf(stderr, "%jd%c", hash_[i], i+1<hash_.size()? ' ':'\n');
  }
};

struct DML {
  using Tags = std::vector<intmax_t>;
  std::string filename;
  std::vector<std::pair<Tags, std::string>> contents;
  DML(const std::string &filename, const std::string &file):
    filename(filename)
  {
    std::pair<Tags, std::string> opened;
    for (size_t i=0; i<file.size(); ++i) {
      if (file[i] == '<') {
        ++i;
        if (file[i] == '/') {
          while (file[i] != '>') ++i;
          contents.push_back(opened);
          opened.first.pop_back();
          opened.second = "";
        } else {
          std::string tag;
          while (file[i] != '>') tag += file[i++];
          if (tag == "br") {
            opened.second += '\n';
          } else {
            contents.emplace_back(opened);
            opened.first.emplace_back(RollingHash<>(tag).hash());
            opened.second = "";
          }
        }
        continue;
      }
      opened.second += file[i];
    }
  }
};

struct DS {
  using Selector = std::vector<intmax_t>;
  using Property = std::pair<Selector, bool>;
  std::map<intmax_t, std::vector<Property>> funcs;

  void add(const std::string &file) {
    for (size_t i=0; i<file.size(); ++i) {
      assert(isalpha(file[i]));
      std::string func;
      while (file[i] != '{') func += file[i++];

      assert(file[i] == '{');
      ++i;

      while (file[i] != '}') {
        while (file[i] != ';') {
          std::vector<std::vector<std::string>> sel;
          std::vector<bool> val;

          std::string id;
          while (isalpha(file[i])) {
            id += file[i++];
          }
          if (file[i] == '.') {
            sel.back().emplace_back(id);
            ++i;
          } else if (file[i] == '!') {
            val.emplace_back(false);
            i += 2;
          } else if (file[i] == '=') {
            val.emplace_back(true);
            ++i;
          } else {
            assert(false);
          }

          assert(sel.back().back() == "true" || sel.back().back() == "false");
          if (sel.back().back()[0] == 'f') {
            val.flip();
          }
          for (size_t i=0; i+1<sel.size(); ++i) {
            std::string id;
            for (size_t j=0; j+1<sel[i].size(); ++j) {
              id += '.';
              id += sel[i][j];
            }
            fprintf(stderr, "%s: %s\n", id.c_str(), val[i]? "true":"false");
          }
        }
      }
    }
  }
};

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<DML> dml;
  DS ds;
  std::map<std::string, size_t> ind;
  for (size_t i=0; i<N; ++i) {
    char buf[32], file[512];
    scanf("%s %s", buf, file);
    std::string filename=buf;
    if (filename.back() == 's') {
      ds.add(file);
    } else {
      dml.emplace_back(filename, file);
      ind[filename] = i+1;
    }
  }

  int M;
  scanf("%d", &M);
  for (int i=0; i<M; ++i) {
    size_t w, h;
    int s;
    char buf[32];
    scanf("%zu %zu %d %s", &w, &h, &s, buf);
    std::string startfile=buf;
    size_t cur=ind[startfile+".dml"];
    assert(cur > 0);

    for (int j=0; j<s; ++j) {
      size_t x, y;
      scanf("%zu %zu", &x, &y);

      
    }
  }
}

