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

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

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

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

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

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

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