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

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

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

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

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

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

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