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

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

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

i.v = g
i.x = f
j.x = h
g.x = h
h.x = j
m.v = j
m.x = i
f.v = h
f.x = m
assert j.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.x: A = None
        self.txt = txt

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

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

i.v = g
i.x = f
j.x = h
g.x = h
h.x = j
m.v = j
m.x = i
f.v = h
f.x = m
assert j.x.x.x.x.x.txt == "h"