#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};
int main() {
  ll t;
  cin >> t;
  for (ll _ = 0, __len = (t); _ < __len; ++_) {
    ll n;
    string a, b;
    cin >> n >> a >> b;
    vl ans;
    ll i = n - 1;
    while (i > 0) {
      if (a[0] == b[i]) {
        ans.push_back(0);
        if (a[0] == '0')
          a[0] = '1';
        else
          a[0] = '0';
      }
      ans.push_back(i);
      for (ll j = 0, j_len = ((i + 1) / 2); j < j_len; ++j)
        swap(a[j], a[i - j]);
      for (ll j = 0, j_len = (i + 1); j < j_len; ++j) {
        if (a[j] == '0')
          a[j] = '1';
        else
          a[j] = '0';
      }
      for (; i > 0; i--)
        if (a[i] != b[i]) break;
    }
    if (a[0] != b[0]) ans.push_back(0);
    ll m = ans.size();
    cout << m << ' ';
    for (ll j = 0, j_len = (m); j < j_len; ++j)
      cout << ans[j] + 1 << (j == m - 1 ? '\n' : ' ');
  }
}
