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

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

e = A("e")
l = B("l")
j = A("j")
i = A("i")
d = B("d")
m = A("m")
g = B("g")

e.o = g
l.p = i
j.o = d
i.o = g
d.p = m
m.o = l
g.p = e
assert l.p.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

e = A("e")
l = B("l")
j = A("j")
i = A("i")
d = B("d")
m = A("m")
g = B("g")

e.o = g
l.p = i
j.o = d
i.o = g
d.p = m
m.o = l
g.p = e
assert l.p.o.p.txt == "e"