#include <bits/stdc++.h>
using namespace std;
template <typename T>
void sorted(vector<long long int> &arr) {
  sort(arr.begin(), arr.end());
}
void coutarr(vector<long long int> arr) {
  long long int n = arr.size();
  for (long long int i = 0; i < n; i++) cout << arr[i] << " ";
  cout << '\n';
}
void coutarr2(vector<vector<long long int>> arr) {
  long long int n = arr.size();
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < arr[i].size(); j++) cout << arr[i][j] << " ";
    cout << '\n';
  }
}
void couta(long long int x) { cout << to_string(x) << " " << x << '\n'; }
void coutpair(vector<pair<long long int, long long int>> arr) {
  long long int n = arr.size();
  for (long long int i = 0; i < n; i++) cout << arr[i].first << " ";
  cout << '\n';
  for (long long int i = 0; i < n; i++) cout << arr[i].second << " ";
  cout << '\n';
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
string revbit(string &s, long long int k) {
  for (long long int i = 0; i <= k; i++) {
    if (s[i] == '1')
      s[i] = '0';
    else
      s[i] = '1';
  }
  for (long long int i = 0; i < (k + 1) / 2; i++) swap(s[i], s[k - i]);
  return s;
}
void solve() {
  long long int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  long long int ct = n - 1;
  vector<long long int> ans;
  while (ct >= 0) {
    if (b[ct] != a[0]) {
      a = revbit(a, ct);
      ans.push_back(ct + 1);
    } else {
      if (a[0] == '1')
        a[0] = '0';
      else
        a[0] = '1';
      ans.push_back(1);
    }
    while (a[ct] == b[ct]) ct--;
  }
  cout << ans.size() << " ";
  coutarr(ans);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int u = 1;
  cin >> u;
  while (u--) {
    solve();
  }
  return 0;
}
