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

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

k = A("k")
e = B("e")
g = B("g")
a = A("a")
c = B("c")
f = A("f")
m = B("m")

k.o = g
e.v = k
g.v = k
a.o = e
c.v = a
f.o = g
m.v = a
assert g.v.o.v.o.v.o.v.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

k = A("k")
e = B("e")
g = B("g")
a = A("a")
c = B("c")
f = A("f")
m = B("m")

k.o = g
e.v = k
g.v = k
a.o = e
c.v = a
f.o = g
m.v = a
assert g.v.o.v.o.v.o.v.txt == "k"