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

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

k = A("k")
f = B("f")
b = A("b")
h = B("h")
g = B("g")
m = A("m")
l = B("l")
i = B("i")
n = B("n")
d = B("d")

k.p = m
k.t = m
f.o = d
b.p = k
b.t = m
h.o = l
g.o = f
m.p = k
m.t = b
l.o = h
i.o = g
n.o = g
d.o = g
assert d.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.t: A = None
        self.txt = txt

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

k = A("k")
f = B("f")
b = A("b")
h = B("h")
g = B("g")
m = A("m")
l = B("l")
i = B("i")
n = B("n")
d = B("d")

k.p = m
k.t = m
f.o = d
b.p = k
b.t = m
h.o = l
g.o = f
m.p = k
m.t = b
l.o = h
i.o = g
n.o = g
d.o = g
assert d.o.o.o.o.o.txt == "f"