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

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

n = A("n")
m = B("m")
i = A("i")
h = A("h")
g = A("g")
d = B("d")
a = A("a")

n.s = m
n.p = i
m.v = d
i.s = d
i.p = h
h.s = d
h.p = n
g.s = d
g.p = a
d.v = m
a.s = d
a.p = n
assert i.p.s.v.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.p: A = None
        self.txt = txt

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

n = A("n")
m = B("m")
i = A("i")
h = A("h")
g = A("g")
d = B("d")
a = A("a")

n.s = m
n.p = i
m.v = d
i.s = d
i.p = h
h.s = d
h.p = n
g.s = d
g.p = a
d.v = m
a.s = d
a.p = n
assert i.p.s.v.v.v.v.v.txt == "m"