#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n;
string a, b;
void solve() {
  cin >> n;
  cin >> a >> b;
  vector<int> ans;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] != b[i]) {
      if (a[0] == b[i]) {
        ans.push_back(1);
        a[0] = '0' + (1 - (a[0] - '0'));
      }
      ans.push_back(i + 1);
      reverse(a.begin(), a.begin() + i + 1);
      for (int j = 0; j <= i; j++) a[j] = '0' + (1 - (a[j] - '0'));
    }
  }
  cout << ans.size() << " ";
  for (int i : ans) cout << i << " ";
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  cin >> T;
  for (int tt = 1; tt <= T; ++tt) {
    solve();
  }
  return 0;
}
