#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    int k = 0;
    int c[3 * n];
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] == b[i]) {
        continue;
      } else {
        if (a[0] != a[i]) {
          if (a[0] == '1')
            a[0] = '0';
          else
            a[0] = '1';
          c[k] = 1;
          k++;
        }
        for (int j = 0; j <= i; j++) {
          if (a[j] == '0')
            a[j] = '1';
          else
            a[j] = '0';
        }
        reverse(a.begin(), a.begin() + i + 1);
        c[k] = i + 1;
        k++;
      }
    }
    cout << k << " ";
    for (int i = 0; i < k; i++) {
      cout << c[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
