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

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

a = A("a")
i = B("i")
f = B("f")
c = A("c")
e = A("e")

a.v = e
i.p = f
i.z = a
f.p = i
f.z = c
c.v = a
e.v = c
assert i.z.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.p: B = None
        self.z: A = None
        self.txt = txt

a = A("a")
i = B("i")
f = B("f")
c = A("c")
e = A("e")

a.v = e
i.p = f
i.z = a
f.p = i
f.z = c
c.v = a
e.v = c
assert i.z.v.v.v.v.txt == "e"