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

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

i = A("i")
j = B("j")
g = A("g")
e = A("e")
m = B("m")
f = B("f")

i.v = g
j.w = f
g.v = e
e.v = i
m.w = j
f.w = j
assert i.v.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.w: B = None
        self.txt = txt

i = A("i")
j = B("j")
g = A("g")
e = A("e")
m = B("m")
f = B("f")

i.v = g
j.w = f
g.v = e
e.v = i
m.w = j
f.w = j
assert i.v.v.v.v.txt == "g"