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

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

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

g.p = a
g.s = b
j.o = a
h.o = m
n.o = b
i.o = b
m.p = g
m.s = f
a.p = g
a.s = m
b.p = f
b.s = a
f.p = b
f.s = b
assert n.o.p.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.s: A = None
        self.txt = txt

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

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

g.p = a
g.s = b
j.o = a
h.o = m
n.o = b
i.o = b
m.p = g
m.s = f
a.p = g
a.s = m
b.p = f
b.s = a
f.p = b
f.s = b
assert n.o.p.s.p.txt == "f"