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

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

l = A("l")
m = B("m")
h = B("h")
i = A("i")
k = A("k")
g = A("g")

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

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

l = A("l")
m = B("m")
h = B("h")
i = A("i")
k = A("k")
g = A("g")

l.p = m
l.s = h
m.o = k
m.v = l
h.o = g
h.v = g
i.p = m
i.s = m
k.p = h
k.s = h
g.p = m
g.s = h
assert l.p.o.p.v.s.v.txt == "g"