Problem: Anfisa the monkey got disappointed in word processors as they aren't good enough at reflecting all the range of her emotions, that's why she decided to switch to graphics editors. Having opened the BerPaint, she saw a white rectangle W × H in size which can be painted on. First Anfisa learnt to navigate the drawing tool which is used to paint segments and quickly painted on that rectangle a certain number of black-colored segments. The resulting picture didn't seem bright enough to Anfisa, that's why she turned her attention to the "fill" tool which is used to find a point on the rectangle to paint and choose a color, after which all the area which is the same color as the point it contains, is completely painted the chosen color. Having applied the fill several times, Anfisa expressed her emotions completely and stopped painting. Your task is by the information on the painted segments and applied fills to find out for every color the total area of the areas painted this color after all the fills.

Input

The first input line has two integers W and H (3 ≤ W, H ≤ 104) — the sizes of the initially white rectangular painting area. The second line contains integer n — the number of black segments (0 ≤ n ≤ 100). On the next n lines are described the segments themselves, each of which is given by coordinates of their endpoints x1, y1, x2, y2 (0 < x1, x2 < W, 0 < y1, y2 < H). All segments have non-zero length. The next line contains preset number of fills m (0 ≤ m ≤ 100). Each of the following m lines defines the fill operation in the form of "x y color", where (x, y) are the coordinates of the chosen point (0 < x < W, 0 < y < H), and color — a line of lowercase Latin letters from 1 to 15 symbols in length, determining the color. All coordinates given in the input are integers. Initially the rectangle is "white" in color, whereas the segments are drawn "black" in color.

Output

For every color present in the final picture print on the single line the name of the color and the total area of areas painted that color with an accuracy of 10 - 6. Print the colors in any order. 

Examples

Input

4 5
6
1 1 1 3
1 3 3 3
3 3 3 1
3 1 1 1
1 3 3 1
1 1 3 3
2
2 1 red
2 2 blue


Output

blue 0.00000000
white 20.00000000


Input

5 5
5
1 1 2 2
2 2 4 2
4 2 4 4
4 4 2 4
2 4 2 2
2
3 3 black
3 3 green


Output

green 4.00000000
white 21.00000000


Input

7 4
9
1 2 2 3
2 3 3 2
3 2 2 1
2 1 1 2
3 2 4 2
4 2 5 3
5 3 6 2
6 2 5 1
5 1 4 2
2
2 2 black
2 2 red


Output

red 2.00000000
white 26.00000000

Note

Initially the black segments painted by Anfisa can also be painted a color if any of the chosen points lays on the segment. The segments have areas equal to 0. That is why if in the final picture only parts of segments is painted some color, then the area, painted the color is equal to 0.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
const int MAXREGN = 1000005;
const double error = 1e-6;
struct Point {
  double x, y;
  Point operator-(const Point other) {
    Point ret;
    ret.x = x - other.x;
    ret.y = y - other.y;
    return ret;
  }
};
struct Segment {
  Point a, b;
  bool operator<(const Segment other) const {
    if (fabs(a.y - other.a.y) > error)
      return a.y + error < other.a.y;
    else
      return b.y + error < other.b.y;
  }
};
struct FillOp {
  Point p;
  string color;
};
struct Region {
  Segment top, bot;
  bool isLine;
};
Segment sa[MAXN], vsa[MAXN];
FillOp foa[MAXN];
Region ra[MAXREGN];
int colorindexarr[MAXREGN];
int rn;
vector<int> gra[MAXREGN];
vector<double> upv;
int preindex, curindex;
vector<Segment> segvec;
int W, H, n, m, vsan;
map<string, int> colormap;
map<int, string> colorantimap;
int colorn;
double areaa[MAXN];
bool colorvisited[MAXN], dfsvisited[MAXREGN];
bool Equals(double a, double b) { return fabs(a - b) < error; }
bool Bigger(double a, double b) { return a > b + error; }
bool Smaller(double a, double b) { return a + error < b; }
bool BiggerEquals(double a, double b) { return Bigger(a, b) || Equals(a, b); }
bool SmallerEquals(double a, double b) { return Smaller(a, b) || Equals(a, b); }
Point MakePoint(double x, double y) {
  Point ret;
  ret.x = x;
  ret.y = y;
  return ret;
}
Segment MakeSegment(double x0, double y0, double x1, double y1) {
  Segment ret;
  ret.a = MakePoint(x0, y0);
  ret.b = MakePoint(x1, y1);
  return ret;
}
Region MakeRegion(bool isLine, double x0, double y0, double x1, double y1,
                  double x2 = 0, double y2 = 0, double x3 = 0, double y3 = 0) {
  Region ret;
  ret.isLine = isLine;
  ret.top = MakeSegment(x0, y0, x1, y1);
  ret.bot = MakeSegment(x2, y2, x3, y3);
  if (isLine) ret.bot = ret.top;
  return ret;
}
Region MakeRegion(bool isLine, Segment s0, Segment s1) {
  return MakeRegion(isLine, s0.a.x, s0.a.y, s0.b.x, s0.b.y, s1.a.x, s1.a.y,
                    s1.b.x, s1.b.y);
}
Region MakeRegion(bool isLine, Segment s0) {
  return MakeRegion(isLine, s0, s0);
}
double CrossProduct(Point p0, Point p1) { return p0.x * p1.y - p1.x * p0.y; }
bool Intersect(Segment s0, Segment s1, Point& retp) {
  double D;
  D = CrossProduct(s0.b - s0.a, s1.b) - CrossProduct(s0.b - s0.a, s1.a);
  if (Bigger(CrossProduct(s0.b - s0.a, s1.a - s0.a) *
                 CrossProduct(s0.b - s0.a, s1.b - s0.a),
             0) ||
      Bigger(CrossProduct(s1.b - s1.a, s0.a - s1.a) *
                 CrossProduct(s1.b - s1.a, s0.b - s1.a),
             0))
    return false;
  if (Equals(D, 0)) return false;
  retp.x = ((s0.b.x - s0.a.x) * CrossProduct(s1.a, s1.b) -
            (s1.b.x - s1.a.x) * CrossProduct(s0.a, s0.b)) /
           D;
  retp.y = ((s0.b.y - s0.a.y) * CrossProduct(s1.a, s1.b) -
            (s1.b.y - s1.a.y) * CrossProduct(s0.a, s0.b)) /
           D;
  return true;
}
Point GetPointAtSegByX(Segment s, double x) {
  Point ret;
  if (Bigger(s.a.x, s.b.x)) swap(s.a, s.b);
  if (Equals(s.a.x, s.b.x)) {
    ret.x = ret.y = -1;
    return ret;
  }
  ret.x = x;
  ret.y = (x - s.a.x) / (s.b.x - s.a.x) * (s.b.y - s.a.y) + s.a.y;
  return ret;
}
bool ParallelAndTouched(Segment s0, Segment s1) {
  if (Equals(s0.a.x, s0.b.x)) {
    return (Equals(s1.a.x, s1.b.x) && Equals(s0.a.x, s1.a.x) &&
            SmallerEquals(min(s0.a.y, s0.b.y), max(s1.a.y, s1.b.y)) &&
            BiggerEquals(max(s0.a.y, s0.b.y), min(s1.a.y, s1.b.y)));
  } else {
    return (!Equals(s1.a.x, s1.b.x) &&
            SmallerEquals(min(s0.a.x, s0.b.x), max(s1.a.x, s1.b.x)) &&
            BiggerEquals(max(s0.a.x, s0.b.x), min(s1.a.x, s1.b.x)) &&
            Equals(GetPointAtSegByX(s0, s1.a.x).y, s1.a.y) &&
            Equals(GetPointAtSegByX(s0, s1.b.x).y, s1.b.y));
  }
}
bool CutSegByIntv(Segment s, double x0, double x1, Segment& outputSeg) {
  if (Bigger(s.a.x, s.b.x)) swap(s.a, s.b);
  if (Equals(s.a.x, s.b.x) || BiggerEquals(x0, s.b.x) ||
      SmallerEquals(x1, s.a.x))
    return false;
  else {
    outputSeg.a = GetPointAtSegByX(s, max(s.a.x, x0));
    outputSeg.b = GetPointAtSegByX(s, min(s.b.x, x1));
    return true;
  }
}
bool IsTouched(Region r0, Region r1) {
  if (r0.isLine) {
    return Equals(r0.top.b.y, r1.top.a.y);
  } else {
    Segment touchSeg;
    touchSeg.a.x = touchSeg.b.x = r0.bot.b.x;
    touchSeg.a.y = max(r0.top.b.y, r1.top.a.y);
    touchSeg.b.y = min(r0.bot.b.y, r1.bot.a.y);
    if (BiggerEquals(touchSeg.a.y, touchSeg.b.y))
      return false;
    else {
      bool updated = true;
      while (updated) {
        updated = false;
        for (int i = 0; i < n; i++)
          if (Equals(sa[i].a.x, sa[i].b.x) && Equals(sa[i].a.x, touchSeg.a.x) &&
              SmallerEquals(min(sa[i].a.y, sa[i].b.y), touchSeg.a.y) &&
              Smaller(touchSeg.a.y, max(sa[i].a.y, sa[i].b.y))) {
            updated = true;
            touchSeg.a.y = max(sa[i].a.y, sa[i].b.y);
            break;
          }
      }
      return Smaller(touchSeg.a.y, touchSeg.b.y);
    }
  }
}
bool isLineRegTouched(Region line, Region reg) {
  if (reg.isLine) swap(line, reg);
  if (Equals(line.top.a.x, line.top.b.x)) {
    return (Equals(line.top.a.x, reg.top.a.x) &&
                SmallerEquals(reg.top.a.y, max(line.top.a.y, line.top.b.y)) &&
                BiggerEquals(reg.bot.a.y, min(line.top.a.y, line.top.b.y)) ||
            Equals(line.top.a.x, reg.top.b.x) &&
                SmallerEquals(reg.top.b.y, max(line.top.a.y, line.top.b.y)) &&
                BiggerEquals(reg.bot.b.y, min(line.top.a.y, line.top.b.y)));
  } else if (SmallerEquals(reg.top.a.x, max(line.top.a.x, line.top.b.x)) &&
             BiggerEquals(reg.top.b.x, min(line.top.a.x, line.top.b.x))) {
    return (
        Equals(GetPointAtSegByX(line.top, reg.top.a.x).y, reg.top.a.y) &&
            Equals(GetPointAtSegByX(line.top, reg.top.b.x).y, reg.top.b.y) ||
        Equals(GetPointAtSegByX(line.top, reg.bot.a.x).y, reg.bot.a.y) &&
            Equals(GetPointAtSegByX(line.top, reg.bot.b.x).y, reg.bot.b.y));
  } else
    return false;
}
bool InRegion(Point p, Region r) {
  if (r.isLine) {
    Segment seg = r.top;
    if (Bigger(seg.a.x, seg.b.x)) swap(seg.a, seg.b);
    if (Equals(seg.a.x, seg.b.x)) {
      if (Equals(p.x, seg.a.x) && SmallerEquals(min(seg.a.y, seg.b.y), p.y) &&
          SmallerEquals(p.y, max(seg.a.y, seg.b.y)))
        return true;
      else
        return false;
    } else {
      if (SmallerEquals(seg.a.x, p.x) && SmallerEquals(p.x, seg.b.x) &&
          Equals(GetPointAtSegByX(seg, p.x).y, p.y))
        return true;
      else
        return false;
    }
  } else
    return SmallerEquals(r.top.a.x, p.x) && SmallerEquals(p.x, r.top.b.x) &&
           SmallerEquals(GetPointAtSegByX(r.top, p.x).y, p.y) &&
           SmallerEquals(p.y, GetPointAtSegByX(r.bot, p.x).y);
}
double CalcArea(Region r) {
  if (r.isLine)
    return 0;
  else
    return (r.bot.a.y - r.top.a.y + r.bot.b.y - r.top.b.y) *
           (r.top.b.x - r.top.a.x) / 2;
}
void AddEdge(int a, int b) {
  gra[a].push_back(b);
  gra[b].push_back(a);
  return;
}
void RelateRegionWithVerticalLine(Region r, int index) {
  if (r.isLine) r.bot = r.top, r.isLine = false;
  for (int i = 0; i < vsan; i++)
    if (isLineRegTouched(ra[i], r)) AddEdge(i, index);
  return;
}
void DFS(int nowp, int from, int to) {
  dfsvisited[nowp] = true;
  colorindexarr[nowp] = to;
  for (vector<int>::iterator iter = gra[nowp].begin(); iter != gra[nowp].end();
       iter++)
    if (!dfsvisited[*iter] && colorindexarr[*iter] == from)
      DFS(*iter, from, to);
  return;
}
int main() {
  double prex;
  rn = colorn = vsan = 0;
  cin >> W >> H >> n;
  for (int i = 0; i < n; i++)
    cin >> sa[i].a.x >> sa[i].a.y >> sa[i].b.x >> sa[i].b.y;
  cin >> m;
  for (int i = 0; i < m; i++) cin >> foa[i].p.x >> foa[i].p.y >> foa[i].color;
  colorantimap[colorn] = "black", colormap["black"] = colorn++;
  colorantimap[colorn] = "white", colormap["white"] = colorn++;
  for (int i = 0; i < m; i++)
    if (colormap.find(foa[i].color) == colormap.end())
      colorantimap[colorn] = foa[i].color, colormap[foa[i].color] = colorn++;
  for (int i = 0; i < n; i++)
    if (Equals(sa[i].a.x, sa[i].b.x)) {
      vsa[vsan++] = sa[i];
      colorindexarr[rn] = colormap["black"];
      ra[rn++] = MakeRegion(true, sa[i]);
    }
  for (int i = 0; i < vsan; i++)
    for (int j = 0; j < i; j++)
      if (ParallelAndTouched(vsa[i], vsa[j])) AddEdge(i, j);
  upv.clear();
  for (int i = 0; i < n; i++) {
    Point ip;
    upv.push_back(sa[i].a.x);
    upv.push_back(sa[i].b.x);
    for (int j = i + 1; j < n; j++)
      if (Intersect(sa[i], sa[j], ip)) upv.push_back(ip.x);
  }
  upv.push_back(0);
  upv.push_back(W);
  sort(upv.begin(), upv.end());
  upv.erase(unique(upv.begin(), upv.end()), upv.end());
  prex = -1;
  preindex = curindex = -1;
  for (vector<double>::iterator iter0 = upv.begin(); iter0 != upv.end();
       iter0++)
    if (prex < 0)
      prex = *iter0;
    else if (preindex < 0) {
      double nowx = *iter0;
      curindex = rn;
      colorindexarr[rn] = colormap["white"];
      ra[rn++] = MakeRegion(false, prex, 0, nowx, 0, prex, H, nowx, H);
      RelateRegionWithVerticalLine(ra[rn - 1], rn - 1);
      prex = *iter0;
      preindex = curindex;
      curindex = rn;
    } else {
      double nowx = *iter0;
      Segment temSeg, prevSeg;
      segvec.clear();
      for (int i = 0; i < n; i++)
        if (CutSegByIntv(sa[i], prex, nowx, temSeg)) segvec.push_back(temSeg);
      segvec.push_back(MakeSegment(prex, H, nowx, H));
      sort(segvec.begin(), segvec.end());
      prevSeg = MakeSegment(prex, 0, nowx, 0);
      for (vector<Segment>::iterator iter1 = segvec.begin();
           iter1 != segvec.end(); iter1++) {
        if (!ParallelAndTouched(prevSeg, *iter1)) {
          colorindexarr[rn] = colormap["white"];
          ra[rn++] = MakeRegion(false, prevSeg, *iter1);
          RelateRegionWithVerticalLine(ra[rn - 1], rn - 1);
          if (!Equals(prevSeg.a.y, 0)) AddEdge(rn - 1, rn - 2);
          if (!Equals((*iter1).a.y, H)) AddEdge(rn - 1, rn);
        }
        if (!Equals((*iter1).a.y, H)) {
          colorindexarr[rn] = colormap["black"];
          ra[rn++] = MakeRegion(true, *iter1);
          RelateRegionWithVerticalLine(ra[rn - 1], rn - 1);
          prevSeg = *iter1;
        }
      }
      for (int i = preindex, jstart = curindex; i < curindex; i++) {
        while (jstart < rn && Smaller(ra[jstart].bot.a.y, ra[i].top.b.y))
          jstart++;
        for (int j = jstart; j < rn; j++) {
          if (Bigger(ra[jstart].top.a.y, ra[i].bot.b.y)) break;
          if (ra[i].isLine == ra[j].isLine && IsTouched(ra[i], ra[j]))
            AddEdge(i, j);
        }
      }
      prex = *iter0;
      preindex = curindex;
      curindex = rn;
    }
  for (int i = 0; i < m; i++) {
    bool found = false;
    for (int j = 0; j < rn; j++)
      if (ra[j].isLine && InRegion(foa[i].p, ra[j])) {
        memset(dfsvisited, 0, sizeof(dfsvisited));
        if (colorindexarr[j] != colormap[foa[i].color])
          DFS(j, colorindexarr[j], colormap[foa[i].color]);
        found = true;
        break;
      }
    if (!found)
      for (int j = 0; j < rn; j++)
        if (!ra[j].isLine && InRegion(foa[i].p, ra[j])) {
          memset(dfsvisited, 0, sizeof(dfsvisited));
          if (colorindexarr[j] != colormap[foa[i].color])
            DFS(j, colorindexarr[j], colormap[foa[i].color]);
          found = true;
          break;
        }
  }
  for (int i = 0; i < rn; i++)
    areaa[colorindexarr[i]] += CalcArea(ra[i]),
        colorvisited[colorindexarr[i]] = true;
  for (int i = 0; i < colorn; i++)
    if (colorvisited[i])
      printf("%s %.6lf\n", colorantimap[i].c_str(), areaa[i]);
  return 0;
}