// Arup Guha
// 2/27/06
// Solution to COP 3530 Spring 2006 Recitation #3B: Sum Solver
// Given a polynomial with integer coefficients to be summed, this
// program determines that sum.

import java.io.*;
import java.util.*;

public class Sum {

  public static void main(String[] args) throws IOException {

    Scanner stdin = new Scanner(System.in);

    // Get the input file.
    System.out.println("Enter the file with the input data.");
    String file = stdin.next();

    Scanner fin = new Scanner(new File(file));

    // Read in the number of sums to process.
    int numsums = fin.nextInt();

    // Go through each one.
    for (int casenum=1; casenum<=numsums; casenum++) {

      // Read in the polynomial.
      int degree = fin.nextInt();
      int[] coeff = new int[degree+1];
      for (int i=degree; i>=0; i--)
        coeff[i] = fin.nextInt();

      // Read in the sum bounds.
      int low = fin.nextInt();
      int high = fin.nextInt();

      // Calculate each term in the sum, one by one and add.
      int sum = 0;
      for (int i=low; i<=high; i++) 
        sum += eval(coeff, i);

      // Output the sum.
      System.out.println("Test case "+casenum+": Sum = "+sum+".");

    }

  }

  // Evaulates the polynomial stored in coeff at x using Horner's method.
  // Note: I just used Horner's method to avoid calling the pow method in
  //       the math class which would force me to use doubles.
  public static int eval(int[] coeff, int x) {

    int sum = 0;

    // This method works because it multiplies each coefficent
    // by x exactly i times, where i is the exponent of that
    // coefficient, and then all the terms are naturally getting added.
    for (int i=coeff.length-1; i>=0; i--)
      sum = x*sum + coeff[i];
    return sum;
  }
}