Rivalry Of Code

0

0 votes
Problem

The CS & IT Department students have been facing tough competitions from each other since ages, in being the best in research & innovation. This time CS Department is taken the edge over IT Department by designing a special weather predictor device which inputs previous years data and perform analysis over it to give a prediction of current weather condition. This device needs a unique string code to be unlocked and activated, which is always kept safe with the Head Of Department's Computer. But this time IT Dept. students are able to hack the code over the network and they have distorted the original code by removing some characters and by replacing some characters. The CS Department has to rebuild the code in order to make their device work. You are given the actual code and the distorted code, you have to find the minimum number of operations to be performed to rebuild the distorted code. An operation can be

(1) Adding one or more character(s)

(2) Replacing one character with another.

Adding one or more character does not consume time whereas replacing a single character require one unit of time.

You have to find out the minimum unit of time in which CS Dept. can rebuild the distorted code.

Input :

First line of the input contains an integer T denoting the number of test cases. T test cases follow where each test case contains two lines containing two strings, first line contains the distorted string D, and the next line contains the actual string S.

Output :

Print the minimum unit of time required to rebuild the distorted string.

Constraints :

  • 1 <= T <= 50
  • 1 <= Length Of D <= Length Of S <= 5000
Time Limit: 2
Memory Limit: 2
Source Limit:
Explanation

Test Case #1: We can change three characters in "porrisa" to create "oornima" and then "p" can be appended at the start and "inst" at the last. So only Three Replacement operations are required.

Similarly for Test Case #2

Editor Image

?