#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
string a, b;
void doIt(int p) {
  for (int i = 0; i <= p; i++) {
    if (a[i] == '0')
      a[i] = '1';
    else
      a[i] = '0';
  }
  reverse(a.begin(), a.begin() + p + 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n >> a >> b;
    vector<int> ans;
    for (int i = n - 1; i > 0; i--) {
      if (a[i] == b[i]) continue;
      if (a[0] == b[i]) {
        ans.push_back(1);
        if (a[0] == '1')
          a[0] = '0';
        else
          a[0] = '1';
      }
      doIt(i);
      ans.push_back(i + 1);
    }
    if (a[0] != b[0]) ans.push_back(1);
    cout << ans.size() << " ";
    for (auto x : ans) cout << x << " ";
    cout << '\n';
  }
  return 0;
}
