#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    string target;
    cin >> s >> target;
    vector<int> steps;
    for (int i = 0, j = n - 1; i < s.length() and j >= 0;) {
      if (i == j) {
        if (s[j] == target[j]) {
          j--;
          continue;
        } else {
          steps.push_back(1);
          j--;
          if (s[0] == '1') {
            s[0] = '0';
          } else {
            s[0] = '1';
          }
          continue;
        }
      }
      char a = s[i];
      char b = target[j];
      int aint = a - '0';
      int bint = b - '0';
      if (target[j] == s[j]) {
        j--;
        continue;
      } else {
        if (aint ^ bint > 0) {
          steps.push_back(j + 1);
          reverse(s.begin() + i, s.begin() + j + 1);
          for (int k = 0; k <= j; k++) {
            if (s[k] == '1') {
              s[k] = '0';
            } else {
              s[k] = '1';
            }
          }
        } else {
          steps.push_back(1);
          steps.push_back(j + 1);
          if (s[i] == '1') {
            s[i] = '0';
          } else {
            s[i] = '1';
          }
          reverse(s.begin(), s.begin() + j + 1);
          for (int k = 0; k <= j; k++) {
            if (s[k] == '1') {
              s[k] = '0';
            } else {
              s[k] = '1';
            }
          }
        }
      }
      j--;
    }
    cout << steps.size() << " ";
    if (steps.size() == 0) {
      continue;
    }
    for (int i = 0; i < steps.size(); i++) {
      cout << steps[i] << " ";
    }
    cout << endl;
  }
}
