class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.p: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.u: B = None
        self.v: A = None
        self.txt = txt

h = A("h")
l = B("l")
k = B("k")
b = B("b")
j = A("j")
m = A("m")
f = B("f")
g = B("g")
i = B("i")
a = A("a")

h.r = m
h.p = m
l.u = g
l.v = a
k.u = f
k.v = j
b.u = g
b.v = h
j.r = a
j.p = m
m.r = j
m.p = j
f.u = l
f.v = j
g.u = i
g.v = j
i.u = f
i.v = h
a.r = h
a.p = m
assert h.r.p.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.p: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.u: B = None
        self.v: A = None
        self.txt = txt

h = A("h")
l = B("l")
k = B("k")
b = B("b")
j = A("j")
m = A("m")
f = B("f")
g = B("g")
i = B("i")
a = A("a")

h.r = m
h.p = m
l.u = g
l.v = a
k.u = f
k.v = j
b.u = g
b.v = h
j.r = a
j.p = m
m.r = j
m.p = j
f.u = l
f.v = j
g.u = i
g.v = j
i.u = f
i.v = h
a.r = h
a.p = m
assert h.r.p.r.r.txt == "h"