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

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

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

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

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

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

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