#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int l = 0; l < t; l++) {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<int> ans;
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    for (int i = 0; i < n; i++) {
      if (a[i] == b[i])
        continue;
      else if (b[i] != a[n - 1]) {
        ans.push_back(n - i);
        for (int j = i; j < n; j++) a[j] = a[j] ^ 1;
        reverse(a.begin() + i, a.end());
      } else {
        a[n - 1] = a[n - 1] ^ 1;
        ans.push_back(1);
        for (int j = i; j < n; j++) a[j] = a[j] ^ 1;
        reverse(a.begin() + i, a.end());
        ans.push_back(n - i);
      }
    }
    cout << ans.size() << " ";
    for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
    cout << "\n";
  }
  return 0;
}
