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

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

m = A("m")
h = B("h")
k = B("k")
e = A("e")
j = A("j")
i = A("i")
g = A("g")

m.o = e
h.v = k
h.s = k
k.v = h
k.s = h
e.o = i
j.o = e
i.o = g
g.o = m
assert m.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.v: B = None
        self.s: B = None
        self.txt = txt

m = A("m")
h = B("h")
k = B("k")
e = A("e")
j = A("j")
i = A("i")
g = A("g")

m.o = e
h.v = k
h.s = k
k.v = h
k.s = h
e.o = i
j.o = e
i.o = g
g.o = m
assert m.o.o.o.o.o.txt == "e"