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

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

e = A("e")
i = B("i")
k = B("k")
m = A("m")

e.p = m
e.o = i
i.r = m
i.v = e
k.r = e
k.v = e
m.p = e
m.o = i
assert m.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.o: B = None
        self.txt = txt

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

e = A("e")
i = B("i")
k = B("k")
m = A("m")

e.p = m
e.o = i
i.r = m
i.v = e
k.r = e
k.v = e
m.p = e
m.o = i
assert m.p.p.p.txt == "e"