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

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

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

g.o = b
d.o = e
d.t = a
b.o = n
a.o = g
n.o = a
e.o = l
e.t = i
i.o = b
m.o = a
l.o = e
l.t = m
assert i.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.o: B = None
        self.t: A = None
        self.txt = txt

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

g.o = b
d.o = e
d.t = a
b.o = n
a.o = g
n.o = a
e.o = l
e.t = i
i.o = b
m.o = a
l.o = e
l.t = m
assert i.o.o.o.o.txt == "g"