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

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

a = A("a")
e = B("e")
g = A("g")
h = A("h")
m = B("m")
k = A("k")

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

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

a = A("a")
e = B("e")
g = A("g")
h = A("h")
m = B("m")
k = A("k")

a.v = g
e.v = h
g.v = a
h.v = g
m.v = k
k.v = a
assert g.v.v.v.txt == "a"