#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<long long int> ans;
    for (long long int i = n - 1; i >= 0; i--) {
      if (a[i] != b[i]) {
        if (a[0] == a[i]) {
          ans.push_back(i + 1);
          for (long long int j = 0; j <= i; j++) {
            if (a[j] == '0')
              a[j] = '1';
            else
              a[j] = '0';
          }
          long long int l = i + 1;
          for (long long int j = 0; j < l / 2; j++) {
            swap(a[j], a[l - 1 - j]);
          }
        } else {
          if (a[0] == '0')
            a[0] = '1';
          else
            a[0] = '0';
          ans.push_back(1);
          ans.push_back(i + 1);
          for (long long int j = 0; j <= i; j++) {
            if (a[j] == '0')
              a[j] = '1';
            else
              a[j] = '0';
          }
          long long int l = i + 1;
          for (long long int j = 0; j < l / 2; j++) {
            swap(a[j], a[l - 1 - j]);
          }
        }
      }
    }
    cout << ans.size() << " ";
    for (auto x : ans) cout << x << " ";
    cout << "\n";
  }
}
