tst pc@(arrlvs, arrns, lcas) m = do
    (x : y : l : r : _) <- getLine >>= readLst
    let xyLca = lca lcas x y
    --putStrLn $ "LCA: " ++ show xyLca
    putStrLn $ show (cmp arrlvs (arrns ! x) l r xyLca x + cmp arrlvs (arrns ! y) l r xyLca y - cmp arrlvs (arrns ! xyLca) l r xyLca xyLca)
    tst pc (pred m)
tst pc@(arrlvs, arrns, lcas) m = do
    (x : y : l : r : _) <- getLine >>= readLst
    let xyLca = lca lcas x y
    --putStrLn $ "LCA: " ++ show xyLca
    putStrLn $ show (cmp arrlvs (arrns ! x) l r xyLca x + cmp arrlvs (arrns ! y) l r xyLca y - cmp arrlvs (arrns ! xyLca) l r xyLca xyLca)
    tst pc (pred m)
tst pc@(arrlvs, arrns, lcas) m = do
    (x : y : l : r : _) <- getLine >>= readLst
    let xyLca = lca lcas x y
    --putStrLn $ "LCA: " ++ show xyLca
    putStrLn $ show (cmp arrlvs (arrns ! x) l r xyLca x + cmp arrlvs (arrns ! y) l r xyLca y - cmp arrlvs (arrns ! xyLca) l r xyLca xyLca)
    tst pc (pred m)