#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9 + 7;
const int64_t N = 1e6 + 5;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int64_t t;
  cin >> t;
  while (t--) {
    int64_t n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<int64_t> ans;
    for (int64_t i = n - 1; i >= 0; i--) {
      if (a[i] == b[i]) continue;
      if (a[0] != b[i]) {
        ans.push_back(i + 1);
        int64_t l = 0;
        int64_t r = i;
        while (l <= r) {
          if (a[l] == '1') {
            a[l] = '0';
          } else {
            a[l] = '1';
          }
          if (l != r) {
            if (a[r] == '1') {
              a[r] = '0';
            } else {
              a[r] = '1';
            }
          }
          swap(a[l], a[r]);
          l++;
          r--;
        }
      } else {
        if (a[0] == '1') {
          a[0] = '0';
        } else {
          a[0] = '1';
        }
        int64_t l = 0;
        int64_t r = i;
        while (l <= r) {
          if (a[l] == '1') {
            a[l] = '0';
          } else {
            a[l] = '1';
          }
          if (l != r) {
            if (a[r] == '1') {
              a[r] = '0';
            } else {
              a[r] = '1';
            }
          }
          swap(a[l], a[r]);
          l++;
          r--;
        }
        ans.push_back(1);
        ans.push_back(i + 1);
      }
    }
    cout << ans.size() << " ";
    for (int64_t i : ans) cout << i << " ";
    cout << "\n";
  }
  return 0;
}
