public void solve() throws IOException {
    int t = nextInt();
    for (int i = 0; i < t; i++) {
      String input = nextLine();
      
      int lcount = 0;
      int locount = 0;
      long total = 0;
      for (int j = 0; j < input.length(); j++) {
        if (input.charAt(j) == 'L') {
          total += locount;
          lcount++;
        } else if (input.charAt(j) == 'O') {
          locount += lcount;
        }
      }
      System.out.println(total);
    }
  }