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

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

n = A("n")
d = B("d")
b = A("b")
f = B("f")
i = B("i")
c = B("c")
k = B("k")
j = A("j")
h = B("h")
g = B("g")

n.p = j
n.s = c
d.v = h
d.r = b
b.p = j
b.s = d
f.v = d
f.r = b
i.v = g
i.r = j
c.v = i
c.r = n
k.v = d
k.r = b
j.p = b
j.s = d
h.v = g
h.r = n
g.v = h
g.r = b
assert k.v.v.v.r.p.p.p.s.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.s: B = None
        self.txt = txt

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

n = A("n")
d = B("d")
b = A("b")
f = B("f")
i = B("i")
c = B("c")
k = B("k")
j = A("j")
h = B("h")
g = B("g")

n.p = j
n.s = c
d.v = h
d.r = b
b.p = j
b.s = d
f.v = d
f.r = b
i.v = g
i.r = j
c.v = i
c.r = n
k.v = d
k.r = b
j.p = b
j.s = d
h.v = g
h.r = n
g.v = h
g.r = b
assert k.v.v.v.r.p.p.p.s.v.txt == "h"