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

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

f = A("f")
d = B("d")
h = A("h")
b = B("b")
n = B("n")
i = A("i")
e = B("e")

f.v = i
d.z = b
h.v = f
b.z = n
n.z = d
i.v = h
e.z = n
assert d.z.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

f = A("f")
d = B("d")
h = A("h")
b = B("b")
n = B("n")
i = A("i")
e = B("e")

f.v = i
d.z = b
h.v = f
b.z = n
n.z = d
i.v = h
e.z = n
assert d.z.z.z.z.z.z.z.txt == "b"