drop schema if exists test cascade;
create schema test;

set search_path='test',public;

drop table if exists test.orig;
create table orig (
  oid serial,
  country_code varchar,
  geom geometry(polygon, 3035)
);

alter table orig add constraint pk__orig primary key (oid);
create index sidx__orig on orig using gist (geom);

insert into orig (
  country_code, geom
) values (
  'A', '0103000020DB0B000001000000CA0000006666662608275441C966AB2B371C4E41A20ABCE4112754417411C31E2C1C4E41BB11DA8A162754415F8FB0D0251C4E41AAB5794B1E275441A8C789E8171C4E416BCBAD632B275441E77581F3011C4E41150C84F53A275441003B2AD2E31B4E41154D3654512754417CEA4400C41B4E411C2D355E64275441F33DDC62A91B4E4189BF698178275441785F2FF3901B4E41A8F480697D275441600FBF5A8C1B4E41850EE54B8027544186DBEC988A1B4E415594CBBC8127544158FF84F2861B4E41A9E4133B87275441C378AAF17E1B4E4138B477668A275441C5F67A7A7B1B4E41D7C2650F8F275441656E2EAE771B4E4161DF3FB092275441128F2AC4751B4E41534D92BA962754416BC610DF741B4E41C358D4859A275441F1309DA8731B4E415AE69B1E9F2754418E14B5E2731B4E41BCF2D4EAA22754417CF90155741B4E41701315EBA2275441AD581B55741B4E414D1A8780A6275441EACBDA85751B4E41688ACA80A62754416AFAD385751B4E416A0E2FBCA8275441D16160FD751B4E41202F6FBCA8275441E6C079FD751B4E41A172FAC8AA27544167209DBF741B4E41CEB3639DAE2754411A042DFA701B4E41103C77B4B1275441E893A1FD6B1B4E41E0001960B72754411BB330B0641B4E41F527E06ABD2754412964B5565C1B4E4153542ACBC5275441D0EA11D2541B4E4111AD507DC82754419B870901511B4E415CDA2E2CCB27544178B2C8624A1B4E418CD5B535CC27544166285E3C451B4E4194A512E1CB2754418D913DC33A1B4E41CCC042B2CA27544130DDA8AE301B4E41BB1C9754C82754414044924E241B4E41DCC2597AC72754410CD5A72C221B4E41FB7F037AC72754418E34212C221B4E41F850AF5FC1275441FB034F701A1B4E410CCF755FC1275441A643F56F1A1B4E41F8D79CD8BD275441804AEFBB161B4E41A90660D8BD275441CABAB5BB161B4E41A1373BDCB927544118F41777131B4E417B6E0EDCB927544141BCE476131B4E41C9ACF580B327544174DB5605111B4E41BAF4AE5BAE275441603E9551131B4E41F2CF2CD3AA2754412C05B108171B4E412875EEECA6275441A1D48AD01C1B4E41F3E7B7B9A0275441BF475DEF241B4E41206B6E859A2754411A75D1122B1B4E41B0BF346194275441B23547D22C1B4E412832C23A8F27544155C2DE6C2B1B4E4141A3CE588B2754419AF2477B271B4E41063E175588275441C5D9B309231B4E4110A2D75488275441BF2FF308231B4E412591938584275441BF958F43181B4E41FFEC438584275441F293C842181B4E4123A75CEE82275441CC53AFEC131B4E41AD91A52480275441E24EDC65081B4E41C1754F437F275441AC4053DDFB1A4E41BE8731028127544112ECC480ED1A4E4108FFC520832754410AB47B4DE51A4E4107D7807E85275441B9230C17DD1A4E41E0C319A08D275441DAC84BD5D01A4E4164BD527093275441808E1312C51A4E41AB8FDBCE99275441DF5823AAB51A4E419554B8879E275441A58B605AA71A4E41E21BEE9FA327544165BD68F8901A4E41B0928F1BA5275441DD4C844D891A4E4156744936A5275441C2AE8CA3871A4E4198CAA791A4275441F801C3077D1A4E41E629F10EA52754413826E932771A4E41026D7D3EA627544172C2613C721A4E41B9F41AEFA52754415ED115776D1A4E41342593BDA42754410E135E32681A4E41CD9ECF86A2275441AA59A6A3611A4E41F58E96ED9E2754413D05D6995A1A4E4128087F69992754419103B518521A4E41F3887ADE93275441E8714C5B451A4E41D2E66DEB902754410AB4E4473A1A4E415DC67CEB8E275441D9192E852A1A4E413A44803B8E2754412304F9FC1C1A4E41C2EFC43D8F275441F488EF4D0E1A4E413A1A13BA902754413756A6BC041A4E41C6B961849327544191728BF0FB194E412896304698275441641EEBFDF1194E411CDF3A2D9D27544167DE203AEA194E41BB8B113CA22754413D5CD93BE6194E41F60C316BA9275441BEE61F64E5194E41331DFEF1AC275441C222C052E6194E415CEFD6CDB42754413CCEABB1EA194E416F0C5830BA27544104E16A5BF0194E41478B95CCBF275441062577E0F5194E417DD723BDC4275441F33F68C0FC194E41AF65A281CB275441524A8CF3061A4E41587A5F62D12754419A6710C1101A4E412E90CEDBD42754418C3968AA171A4E413ABC81A0D7275441E0638D671F1A4E416F04EBD3D8275441058F6DCC2A1A4E415E481236DB275441307EBBF63E1A4E41896A8201DE275441A21F52F54D1A4E41642D8808E3275441DE5D24DA591A4E4168CCE7A5E72754413ADCDC54601A4E4160C1B176EA275441DCBE4BF9621A4E41C2DD169FED27544121453871651A4E41B26D4C1AF32754416C09813D671A4E412ECE9C61FB2754415BDC6B2C641A4E41B7EE890005285441E2E3A4735E1A4E41F211CF0C0A2854416C84ADDE581A4E41F8B8C64A0C285441CAFC626C541A4E416A375E1A0F28544139F72DBA4B1A4E41F1A21C48112854413EF51611431A4E41C5DE573E12285441AFF9E08A3C1A4E410DE9742B13285441B6591CF7321A4E419CCCF857132854419970B9F2291A4E41963C0BFC12285441F849A0AA261A4E415160E4CC11285441DFD19C1B241A4E41E514385F0E28544195B067D6211A4E415CA81A970B2854416F0FD2061F1A4E412C2D1C9A02285441366EDA1D0A1A4E413EA96C30FC275441AA0A44F8FC194E41D2422CCEF82754412C600FADF8194E410168DBDCF42754418FAC6D5FF4194E41EE188E98EF2754414EB69C1BE7194E418D5A2414EE275441E370D959E1194E4155053BACEB2754410E5DB068D6194E414173A8FCE727544165BF8163C9194E41239F74A3E627544164D936BCC1194E41A2E8D94AE527544150B68FD6B7194E41424C8BFAE427544110BC41E0AE194E414B093280E527544126DF9AEFA4194E416A184574E6275441308864989F194E412A06148CE827544180C2B86F98194E4142F85A64EB27544132E9C21893194E41D744EF33EF275441D9222F958F194E41A0F893E2F3275441F4F999928E194E411184AADFF7275441C7D0A2B28F194E4179E80BB4FA27544177207F4D92194E41EBBAD0B0FD27544149767E5E96194E41976A6501FF275441548338BA98194E41FF27E06301285441E34588B89D194E41C668B765082854411BFC988CAA194E415DEF891B0C285441D15BCD79AE194E417BF19EE70F285441E6FF9798B0194E411A4E442F162854411680797AB2194E41F0FE64481928544190EBA2B1B0194E41536789651E285441E5F5E824AB194E41BA320CEF23285441A4432D2EA1194E416DE8F5252D28544172CF802E8C194E4185D9A245302854415D1AE2097E194E417393380C31285441240E607F70194E41C229DAE13028544158B74C2A6D194E4160BE136630285441D2635A7163194E41CCBF8B2A2E285441FE8F8DE759194E416B135BBD2928544110BBF66C4F194E411CA5A3EA2528544158BA070E44194E41BF194D7A222854417C6E018434194E41DD76180A21285441A8CC8B1F29194E41A7AD28471F2854410EAF5DD716194E413B6042741E285441434F76EA0E194E412048715A1F2854415474461A01194E41A40C74DA20285441886C2685EF184E41038B6405252854410D63571DD9184E4168E0EDAE27285441C2BEC87DCE184E410CC26AE32C285441AAE729F1C4184E413F53521B332854410078A678BD184E412263CF5E3E28544142BBF48BB4184E41792C05B04A28544122443A8FAE184E4119EBB6445528544119067514AC184E41A869725E5A28544123EFE475AC184E41282941B55D285441F2EA1587AF184E41E5CC147E65285441FC5B9F2DB7184E415A7B0A3470285441ACACF90DBF184E41945354007E2854414A3ACDE4BD184E419600985683285441196EECCBBC184E415C8850EB852854410CD94BB2BA184E41239A40698B285441EEFF9D56B4184E41EC25A15C93285441AFBC39FCA7184E41F244C5E699285441E07F5A8A9C184E41D62706459D2854415C03622894184E4134049C5AA1285441849A30C182184E415FB31F93A628544159FA08016F184E4144EC490FAC2854419CE5CA615B184E413CB03B8AAF285441ABA5DBE24F184E414D228EA5B4285441D311AB7D41184E41FDD8A57DB82854415DDA97733B184E414239645ABE28544108A5E53037184E41F39C71C5C22854416C37440D36184E41FC612513CA285441B8FB87ED35184E41EA2C4992D3285441418BD7F833184E41C60C91BEDB285441AEA061D730184E41AC0F349AE12854414E2B2E232C184E4180E5D058E82854419DEF862124184E41E266F6FDEC285441423CB04B1D184E4160EC6EA9F1285441ED01212715184E413D503F79F7285441AF6D22F308184E41BAB0C001FF285441F288A035F6174E4147D394DE00295441BC14CA3BF1174E4123C4FB9002295441333333B3EC174E416666662608275441333333B3EC174E416666662608275441C966AB2B371C4E41'
), (
  'B', '0103000020DB0B0000010000000F0100006666662608275441333333F33D1C4E419A9999392E295441333333F33D1C4E419A9999392E295441097394CF2B184E41C72D162B2B295441E047F90E30184E415D7A025C2729544182BC497358184E417E2B89F5162954415B470C4E75184E4119012891F92854412C88B87D69184E417515DCFEE5285441E605765D46184E4156CE71A0E0285441480E6EC23C184E41288167B8DD2854416B94CBF032184E41BC54C5C0D82854411A61EF3135184E41203CEAA0D428544134C7636B37184E417A9025EDD0285441FA8E536E38184E41D3753D90CD285441604A1BCA38184E416DB802ACC82854414DD2628B38184E41A8E3E10BC3285441678F0D6F38184E41A8D6FBE3BD2854419B801FA838184E416EE292B9BC2854417F131EB538184E418EB1EEB0B92854412FBF18393A184E41842046BFB72854415E90CA863C184E4197236E30B52854411CBC8CFE40184E419CFF451EB12854414B278FBF48184E41E81B4EE4AD2854412D0BF21951184E41D00352DCAA285441C260322E5A184E41B97B9317A7285441A8C8EDBF66184E414CB2413EA328544152B8C73576184E41A57F893E9E285441611AE5238C184E41AEF24FDD9B285441B6ECECB095184E4140FD82359A28544197F1A0DA9B184E41960F872B982854414ADAD889A1184E41F680D9689428544100568546A8184E4106FE14798C2854417E49E209B5184E417AF50378882854411067C063BC184E41F7E0271B862854416E5BBD8CBF184E4170AFB92384285441357C182EC1184E412F72FCFE8128544179C33534C2184E41DB556FB57F28544156537B2AC3184E41695CD2BC792854414AE18D85C3184E41A10F3F57722854416534CBBBC3184E41AAA3F9976D28544159CDA158C3184E41A3E6290F69285441E99FB8E0C1184E4151425C3365285441D207720EBF184E4192B7726361285441565EA9BDBA184E415A931D8B5C2854412BC927EFB4184E41E1F319325828544190E1DB89AF184E41BA3D1039542854419831283EAC184E4189B867C14D2854418DDB719FA9184E410A8A3B88472854413252117AAA184E41FA07496E402854417D4B7583AD184E412F875400392854417A4BCDC5B3184E41F0548C9E33285441B2202F00B9184E410B0023712C285441724961FCC1184E41F0F2FE81292854411018FFCFC7184E41791CB48B2628544170D3DF83D0184E41696394DC222854417E86F4D6DE184E41BDA934591F2854419159D268F3184E41B224649D1D285441A731ACC100194E410B2E8ABD1C285441AFCFA8770A194E41CE6023941B285441499788661D194E41FD2C98BE1B285441F89B34B624194E4168B60D201C28544172EFF0DC28194E411279644F1D2854415F63E32B2F194E41B4629B5F1F2854416A1B495E36194E4170A24861222854410B11136D40194E4182F399F1262854419251233B4E194E411C785B392A285441DDC01C4456194E41955249762E285441B7F5F99061194E418B50185830285441B996937669194E41EEBCF0B93028544104E005126B194E416255BA7C31285441D8B112B171194E413621415D3128544109E0BF7178194E41245E4A8F3028544144E3D90280194E41646ED2192F285441B008F51988194E41A59199E82B2854415C6F7F8294194E417462760D2828544146053A27A2194E415B32939324285441578B29CCAB194E4188E58344222854419484A9C9B0194E41B5096D4A1F28544100C9F8F8B4194E41D75123BB1C285441D62857FEB7194E416E969A9919285441B4A58E96B9194E41F52716D81628544152974F87BA194E414F99E149142854414D549D68BA194E411C97C7671228544118D2ABFCB9194E41FD55B51D10285441081E7170B8194E4192B1EEB90D285441F43FD4E2B5194E41514CC566092854419207C5B6B0194E413D8CA998052854414E3454F9A9194E4195FDDDC101285441C6817FA1A4194E41C35BEB40FD2754410AB251FA9D194E4129D8F46DFA2754411883086299194E410B398210F227544168307FA98F194E419A534123EF275441A61B65358D194E419E708214EB2754415B70D6488B194E4154BD5C30E82754411B191EEA8A194E415A92F3B0E5275441E0B60F248C194E4122839D94E32754419C631D558E194E4180384C0CE2275441D80379EA90194E41BA4CA0D7E02754411695FF7693194E41AB21D080DF275441DE1A069697194E414D9F4CB1DE2754417CEA02FF9A194E41A4C8DEF9DD2754412789498E9E194E4190078174DD2754413FA2D290A2194E41A983C74CDD2754412583A6E9A5194E41E0C2D960DD2754410C88B01BAA194E41C08263E9DD275441F4BBEC4AAD194E410821DB91DF2754416A752896B5194E4155E41860E0275441318A1F75BA194E412F3A3C6BE12754415159388ABF194E41C31CE757E2275441A8178073C3194E41182F2D75E327544178B71813C7194E4140A8BA85E527544112EA0FF8CC194E41A6293594E9275441F3EA28AAD6194E41416A91D9EA275441C7FF847FDA194E41B2426C5AEE275441C613EFD4E6194E4188258C7AF0275441A17F86DEED194E41DCF5A0A1F2275441BB9AF979F3194E41A4FF5EE0F42754412B75DF9CF7194E413A2BF5D4F727544130D95D57FC194E412F87B08AFB2754412423F321011A4E41E530BE2A022854414B0C00F80A1A4E41363209B20D285441AC0C9F0B231A4E41057E2B6C11285441641B48042B1A4E41AA7FDCF212285441AA843702301A4E41CC34A050132854411C1C3E0B321A4E41BDE167CA13285441EB569BAC341A4E414481810F142854410FA5F65B391A4E411B50E01C142854418F7AA1F93E1A4E41FB2DBF7C1328544182E186E7431A4E410478238112285441E36AE01D491A4E416A6DB85D11285441B8536A154E1A4E419A12F9EB0F285441A2A4C282521A4E41959CD8C40D285441CF18CFBD571A4E41BE096F4E0B28544174B6965E5C1A4E4153ABC2E8082854411610873C601A4E4162AFA9520528544166B292A3631A4E417A3ABCDD032854419B427397641A4E4185364FC4F9275441963A78196B1A4E41B101EFECF52754417208F9986C1A4E41B9D2E215F22754412B9419A56C1A4E41801A68BBEE27544148AC8A966C1A4E41A4198639EA27544182DBAB666B1A4E4124741DACE5275441FDE92F85681A4E41115A2383E127544149F90372641A4E413959F4D3DC275441BC86DE975D1A4E417BF7B70BDA275441042556E5571A4E4140F5FB07D82754418F915E4A511A4E411EFC51A6D6275441466819104B1A4E419121F9E7D52754415BB74AE0431A4E413451BE40D52754416C4848743C1A4E4164C89228D527544198771CD8341A4E41DACB524FD52754418C56C78C291A4E41BA00F2B5D527544101DDB6011E1A4E41D5B5867DD52754414263C4791A1A4E413AFA93C0D4275441CAF0A942131A4E41EB2E860FD4275441AE69EFBF0D1A4E41721DFA47D32754412C5655290A1A4E413C99449FD22754416E444FC1071A4E412D33149AD1275441B111D71F051A4E41B0858D1ED02754413617A54F021A4E4166077271CC27544132DA320FFE194E41286255E8C5275441CF8CED6EF8194E41E3F6581CBF27544157F2E40BF3194E41C93FF706B9275441F742223BED194E41FCB685C3B1275441B605FC52E8194E41C2D71712AD27544144F8692BE6194E41EA2883F1A7275441E855754BE5194E41A08C4570A2275441A2D19CC4E5194E41E65F05939B2754415BBCFCBFE8194E417866A33297275441468A0415ED194E411F1735B9932754415CFCFD8CF1194E4195D03C4B912754413BFB71C8F5194E414ABFF2378F2754416DB0D5CDFA194E41BFF9A5BB8B275441B3C680A3041A4E41DA90741F8B275441171C744F071A4E4152A8A0B28A275441574FA4030A1A4E41CD6C71FE892754414C1D5B73101A4E4180DC81B889275441F75C41A4151A4E41B2C2C79A89275441EC93C58A1A1A4E417C911DEA8927544129E57820201A4E418DD9DB7A8B2754414AAEE5522C1A4E41133324F18C275441F691C95C381A4E4106D63CBD8E2754414C3D1ED0431A4E412774D1C38F275441F666481E491A4E41549E932491275441DED926DE4D1A4E41F14DF7DD922754417B6A03A2531A4E4159D347D894275441B788C1985A1A4E41EC4C971396275441E6A9471E5E1A4E4156854EE59727544178A5C55C621A4E414CA3964C99275441E5701595641A4E41C3FF0C7E9B275441A5AED930671A4E41B393E6F29F27544162846CEA6C1A4E4136037BE8A22754418B2AEFA7711A4E41A42E3810A427544126EBCD2F741A4E41CBEE53DAA42754410E3FF5DB761A4E41DD586D07A6275441DA6F81757C1A4E417C1AA32EA82754418846644F8B1A4E419C00F593A8275441DCE70BA58E1A4E419D15BAB3A8275441F269BF71921A4E4165E9DB22A82754411E1D9769971A4E41F6061A7AA727544188AF8A509D1A4E416CC7F868A627544184F6DFCCA21A4E41CA726AFA91275441733536E6CB1A4E41D5078FDB87275441B6A2F661DF1A4E4105352AFE82275441CDC64248EA1A4E4110A98DDB7F2754410E318C2CF11A4E414194ADB67E2754419C7605E6F51A4E41E2E1BD167E27544195AACA61F91A4E41949752897D27544110D1A4C3FE1A4E41469F0F967D275441BB763889031B4E41EFCF547D7D2754417B8F0676091B4E411B6269BD7D275441872AE04F0E1B4E41437EE0357E2754419E8E625F131B4E41C7AB03367F2754417142FC66181B4E4138189F6E81275441674D5D091E1B4E411C466B4784275441444E5660231B4E41484C3DD7872754419D90B291281B4E4111E9951D8C2754414BE6F09B2D1B4E41E0DA86958F2754411AF137852F1B4E417F3E0B879327544153015FF8301B4E41E2BCB7EC972754413453FFA6301B4E419B4C0E039E2754413358A2742D1B4E4163ACAB81A12754414C8528C8291B4E41A0082BA3A6275441FC0A5DB6221B4E411ABD1D68AF275441765616FD161B4E41651D6C45B3275441B171266E131B4E41B4E4DF72B6275441FFE43955111B4E41EEACC868BA275441611B5199111B4E411292D491BE275441E9944590131B4E41A4EE4EB3C3275441A3BC6B1B171B4E41C4AEAFC2C62754416D679B5E1A1B4E41A7CC4DEBC9275441DE6E14C11E1B4E4131C476C5CB27544190B69E45231B4E41D6DD31D3CC275441E8770A3B281B4E417D3F7C63CD275441A23D314B2E1B4E415D584ECECD275441B92B9DDD371B4E4145D25B34CD275441441C3E45411B4E417FCD0594CC2754415E9A69CD461B4E41AC5C0E1BCC275441C291E278491B4E419A47495ACB275441CACB02194C1B4E41ED1B798BC9275441560ACD0E4F1B4E41C1C59BE7C32754417EBFE81A561B4E411E97C10BC02754413E63CA665A1B4E41612DF413B927544177A6FF31611B4E4122CC92EDB627544174C1FB10641B4E413D145D30AF2754412D186402711B4E412745BDC6AB2754411E85DAC6741B4E41A782523FA9275441080AE476751B4E41ECB32A22A6275441B3504D89741B4E41E0D7CB1DA327544103B0C0FC721B4E411FE46D799F275441E8CE01D1721B4E414F861D2F9A275441D6E9C041731B4E4109EBF0E994275441C26C955E741B4E419FF9321A9127544120CBC6DF751B4E41F72005B08D275441CCB02033781B4E41FA01181D8627544126B4FEB67F1B4E4162BBD2797E2754417BBF574C881B4E417ADC236578275441D83F04D28F1B4E4198A3AF0A672754416E7A0652A71B4E415F025582642754411A6360C5AA1B4E41BE1245455D2754415B9579A5B41B4E4176EE0E554D275441BF019F62CA1B4E410B7A912443275441F98CC78BD71B4E41B5C1ED9A402754412E5BF335DC1B4E4157E669A739275441DF9F4FFDE81B4E41DAF7E5253727544172FCC084ED1B4E41CF104E6120275441498710A9161C4E417DDE85441927544132EA2E48221C4E41B532A95414275441DD2EDE822A1C4E4162F1507E0E275441EC78BF23321C4E4166666626082754410E99466C3A1C4E416666662608275441333333F33D1C4E41'
), (
  'B', '0103000020DB0B000001000000110000006B21790CF5285441C58BEEC60F184E410CCEC684EB285441D6A9E57822184E415EF70F7DE82854413272627927184E411CD254B9E5285441BCFFF6EB2B184E41DBABFD9DE32854415A357AA52E184E410946F245E1285441AAE30DBB30184E41288167B8DD2854416B94CBF032184E4156CE71A0E0285441480E6EC23C184E417515DCFEE5285441E605765D46184E4119012891F92854412C88B87D69184E417E2B89F5162954415B470C4E75184E415D7A025C2729544182BC497358184E41C72D162B2B295441E047F90E30184E419A9999392E295441097394CF2B184E419A9999392E295441333333B3EC174E41630F5EFA02295441333333B3EC174E416B21790CF5285441C58BEEC60F184E41'
);
