input: 
  class Matrix:
      def __init__(self, m, n, lst):
          self.m = m
          self.n = n
          self.mat = []
  
          c = 0
          for i in range(self.m):
              a = []
              for j in range(self.n):
                  a.append(lst[c])
                  c += 1
              self.mat.append(a)
  
      def __str__(self):
          output = ""
          for i in self.mat:
              for j in i:
                  output += str(j) + " "
              output += '\n'
          return output
  
      def add(self, mat2):
          for i in range(self.m):
              for j in range(self.n):
                  self.mat[i][j] += mat2.mat[i][j]
  
      def sub(self, mat2):
          for i in range(self.m):
              for j in range(self.n):
                  self.mat[i][j] -= mat2.mat[i][j]
  
      def mul(self, mat2):
          result = []
          for i in range(self.m):
              a = []
              for j in range(mat2.n):
                  s = 0
                  for k in range(self.n):
                      s += self.mat[i][k] * mat2.mat[k][j]
                  a.append(s)
              result.append(a)
          self.mat = result
          self.m = len(result)
          self.n = len(result[0])
  
      def transpose(self):
          result = [[self.mat[j][i] for j in range(len(self.mat))] for i in range(len(self.mat[0]))]
          self.mat = result
          self.m = len(result)
          self.n = len(result[0])
  
  # Test cases
  matrix1 = Matrix(3, 3, [1, 2, 3, 4, 5, 6, 7, 8, 9])
  matrix2 = Matrix(3, 3, [9, 8, 7, 6, 5, 4, 3, 2, 1])
  matrix1.add(matrix2)
  print(matrix1) # Expected output: 10 10 10 \n 10 10 10 \n 10 10 10 \n
  
  matrix3 = Matrix(2, 2, [1, 2, 3, 4])
  matrix4 = Matrix(2, 2, [5, 6, 7, 8])
  matrix3.sub(matrix4)
  print(matrix3) # Expected output: -4 -4 \n -4 -4 \n
  
  matrix5 = Matrix(2, 3, [1, 2, 3, 4, 5, 6])
  matrix6 = Matrix(3, 2, [7, 8, 9, 10, 11, 12])
  matrix5.mul(matrix6)
  print(matrix5) # Expected output: 58 64 \n 139 154 \n
  
  matrix7 = Matrix(2, 3, [1, 2, 3, 4, 5, 6])
  matrix7.transpose()
  print(matrix7) # Expected output: 1 4 \n 2 5 \n 3 6 \n
  
output:     
      def scalar_mul(self, scalar):
          for i in range(self.m):
              for j in range(self.n):
                  self.mat[i][j] *= scalar
  
      def get_element(self, i, j):
          return self.mat[i][j]
  
      def set_element(self, i, j, value):
          self.mat[i][j] = value
  
  # Test cases
  matrix8 = Matrix(2, 2, [1, 2, 3, 4])
  matrix8.scalar_mul(2)
  print(matrix8) # Expected output: 2 4 \n 6 8 \n
  
  matrix9 = Matrix(2, 2, [1, 2, 3, 4])
  print(matrix9.get_element(1, 1)) # Expected output: 4
  
  matrix10 = Matrix(2, 2, [1, 2, 3, 4])
  matrix10.set_element(1, 1, 10)
  print(matrix10) # Expected output: 1 2 \n 3 10 \n
  