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

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

b = A("b")
f = B("f")
m = A("m")
i = A("i")
e = A("e")
g = B("g")
c = A("c")
a = B("a")

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

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

b = A("b")
f = B("f")
m = A("m")
i = A("i")
e = A("e")
g = B("g")
c = A("c")
a = B("a")

b.o = i
f.p = c
f.t = a
m.o = b
i.o = b
e.o = i
g.p = e
g.t = a
c.o = e
a.p = m
a.t = g
assert e.o.o.o.o.o.txt == "i"