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

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

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

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

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

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