import java.io.*; import java.util.*; public class skill_mb { public static void main(String[] args) throws IOException { Input in = new Input(); int t = in.nextInt(); while (--t >= 0) { long n = in.nextInt(); long a = in.nextInt(); long b = in.nextInt(); long x = in.nextInt(); long y = in.nextInt(); if (a == b || x >= n) { System.out.println(n * a); } else { long answer = a * x; n -= x; if (a * x > b * (x + y)) { answer += a * x * (n / (x + y)); long rem = n % (x + y); answer += Math.max(b * rem, a * (rem - y)); } else { answer += n * b; } System.out.println(answer); } } } private static class Input { byte[] buf = new byte[2048]; int curr, size; char next() throws IOException { if (curr == size) { curr = 0; size = System.in.read(buf); } char rv = (char) buf[curr]; ++curr; return rv; } int nextInt() throws IOException { char ch; while ((ch = next()) <= ' '); int rv = ch - '0'; while ((ch = next()) > ' ') { rv = 10 * rv + (ch - '0'); } return rv; } } }